mchen
mchen

Reputation: 10156

Where is the Immediate Scheduler in rxJava3?

In rxJava 1 there was Scheduler.immediate() which let you schedule work on the current thread. In rxJava 3 I can no longer find this scheduler.

Does anyone know what the replacement for Scheduler.immediate() is in rxJava 3?


My use case:

I have a client-side API which I use to subscribe to an infinite stream of events (e.g. a news feed) from a remote server. The API notifies me of events via a callback which I register:

Observable.create(emitter -> apiClient.registerCallback(event -> emitter.onNext(event)))
        .observeOn(Schedulers.immediate())   // I'd like downstream operators to run on current thread
        .map(myFunc);

However, the API calls my callback from a different thread. I wish to run downstream computations like myFunc on the current thread (the one that created the Observable) so as not to block the API's thread.

Upvotes: 2

Views: 890

Answers (1)

LppEdd
LppEdd

Reputation: 21134

AFAIK, in RxJava 3 you can employ ImmediateThinScheduler to obtain the same effect.
Although it's kept in the internal package, you can use it.

The API is so simple you can actually create one yourself if you don't want to depend on their internal package.

Upvotes: 3

Related Questions