You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #4007 introduced a new way of hooking into the lifecycle of the base reactive types (Observable, Single, Completable) and the Schedulers. The original RxJavaPlugins' design was too much focused on class-initialization time hooking and didn't properly allow hooking up different behavior after that. There is a reset() available on it but sometimes that doesn't work as expected.
The new class rx.plugins.RxJavaHooks allows changing the hooks at runtime, allowing tests to temporarily hook onto an internal behavior and then un-hook once the test completed.
RxJavaHooks.reset();
// or
RxJavaHooks.setOnObservableCreate(null);
It is now also possible to override what Schedulers the Schedulers.computation(), .io() and .newThread() returns without the need to fiddle with Schedulers' own reset behavior:
Observable.just(1).subscribeOn(Schedulers.computation())
.subscribe(v -> System.out.println(Thread.currentThread()));
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).
See ReactiveX/RxJava#4007
As of the filing of this issue, it's still in the planning/proposal stage, but if it gets merged, it'll need some documentation.
Hooks are currently documented over at the RxJava wiki (https://github.com/ReactiveX/RxJava/wiki/Plugins) but it's probably time to consolidate the RxJava documentation over here (see also #238).
The text was updated successfully, but these errors were encountered: