RxJavaPlugins.getInstance 已弃用

RxJavaPlugins.getInstance is deprecated

我覆盖了我的调度程序以进行测试:

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

  })

但是文档说:

Deprecated use the static methods of RxJavaHooks.

如何使用 RxJavaHooks 覆盖那些调度程序?

Release notes for 1.1.7 包含如何在 java 中执行此操作的代码示例。设置计算调度程序的小摘录:

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

还有

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