简体   繁体   中英

RxCpp: Difference bewteen schedulers

For the different kind of coordination that uses a particular scheduler as describedhere . 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?

  • 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM