RxCpp: Difference bewteen schedulers

219 Views Asked by At

For the different kind of coordination that uses a particular scheduler as described here. The available types are:

identity_immediate()
identity_current_thread()
identity_same_worker(worker w)
serialize_event_loop()
serialize_new_thread()
serialize_same_worker(worker w)
observe_on_event_loop()
observe_on_new_thread()

Could anyone help to explain what is the difference between the identity_xxx, serialize_xxx and observe_on_xxx, and when shall each type be used?

1

There are 1 best solutions below

0
Victimsnino On
  • identity_ - it means no synchronization at all. No mutexes or whatever like this. So, it means:
    • identity_immediate - would emit the item immmediately with no scheduler at all
    • identity_current_thread - would schedule emission to the current thread without any syncrhonization (but it is thread local, so, it doesn't need it)
  • observe_on_ - uses a queue-based scheduler. It uses the queue to "serialize" emissions by enqueueing emissions from one thread and then processing this queue from another:
    • observe_on_new_thread - place emission to the queue and process them from a newly created thread
    • observe_on_event_loop - same as before, but it uses a thread pool under the hood
  • serialize_ - use mutexes to provide syncrhonization