Available schedulers

The subscribe_on, observe_on, and factory operators take the scheduler object as a parameter. As its name implies, a scheduler is an object that is responsible for scheduling the emission of the items of an observable. Scheduling the emission means that, instead of calling the observer callbacks directly in the context of the observable, the emission of the items is transferred to another context. RxPY implement two kinds of scheduler: thread schedulers and event loop schedulers. However, the scheduler principle is very generic and it could be possible to implement much more specific schedulers, such as transferring execution to another IP of a chipset or even another device (even though these use cases should rather be implemented as drivers if the code is designed as functional and reactive).

Three schedulers are of interest when developing an AsyncIO application:

  • The NewThread scheduler, to schedule execution on a dedicated thread
  • The ThreadPool scheduler, to schedule execution on a fixed set of worker threads
  • The AsyncIO scheduler, to schedule execution on the event loop

All the schedulers are implemented in the concurency module of RxPY. So, they can be imported this way:

from rx.concurrency import NewThreadScheduler
from rx.concurrency import ThreadPoolScheduler
from rx.concurrency import AsyncIOScheduler
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.26.108