Daniel Gomez Rico
Daniel Gomez Rico

Reputation: 15936

RxJavaPlugins.getInstance is deprecated

I override my schedulers for testing with:

RxJavaPlugins.getInstance().registerSchedulersHook(object : RxJavaSchedulersHook() {
    override fun getIOScheduler() = Schedulers.immediate()
    override fun getComputationScheduler() = Schedulers.immediate()
    override fun getNewThreadScheduler() = Schedulers.immediate()

  })

But docs says:

Deprecated use the static methods of RxJavaHooks.

How can I override those schedulers using RxJavaHooks ?

Upvotes: 2

Views: 1728

Answers (1)

m.ostroverkhov
m.ostroverkhov

Reputation: 1960

Release notes for 1.1.7 contain code samples how to do that in java. Small excerpt for setting computation scheduler:

RxJavaHooks.setOnIOScheduler(current -> Schedulers.immediate())
RxJavaHooks.setOnComputationScheduler(current -> Schedulers.immediate())
RxJavaHooks.setOnNewThreadScheduler(current -> Schedulers.immediate())

There is also

By default, all RxJavaHooks delegate to the original RxJavaPlugins callbacks so if you have hooks the old way, they still work. RxJavaHooks.reset() resets to this delegation and RxJavaHooks.clear() clears all hooks (i.e., everything becomes a pass-through hook).

Upvotes: 10

Related Questions