The subscribeOn
operator in RxJS library allows us to specify on which scheduler we want to subscribe to a Observable
. This can be useful when we want to delay the subscription to an Observable until a certain time, or when we want to make sure that the subscription is done on a specific thread or context.
Here's an example of how to use subscribeOn
to subscribe to an Observable on a separate scheduler:
index.tsx445 chars18 lines
In this example, we are using the asyncScheduler
to subscribe to the click$
Observable, which means that the click$
events will be processed on a separate thread from the main UI thread. This is useful when we don't want the event processing to block the UI.
Note that subscribeOn
only affects the subscription of the Observable, and not the emission of the events. If you want to control the emission of events, you can use the observeOn
operator instead.
gistlibby LogSnag