Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 402
Daniel Gomez Rico Avatar asked Aug 02 '26 16:08

Daniel Gomez Rico


1 Answers

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).

like image 126
m.ostroverkhov Avatar answered Aug 04 '26 07:08

m.ostroverkhov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!