2.x: CreateEmitter throws when onError called after dispose unlike 1.x
See original GitHub issueI have these two tests which behave differently in 1.x and 2.x.
@org.junit.Test
public void testRxJava1() throws Exception {
Subscription subscription = rx.Observable.fromEmitter(emitter -> {
emitter.onNext(1);
emitter.setCancellation(() -> emitter.onError(new IllegalArgumentException()));
}, Emitter.BackpressureMode.NONE)
.subscribe(
integer -> System.out.println(integer),
throwable -> throwable.printStackTrace()
);
subscription.unsubscribe();
}
@org.junit.Test
public void testRxJava2() throws Exception {
Disposable disposable = Observable.create(emitter -> {
emitter.onNext(1);
emitter.setCancellable(() -> emitter.onError(new IllegalArgumentException()));
}).subscribe(
integer -> System.out.println(integer),
throwable -> throwable.printStackTrace()
);
disposable.dispose();
}
The 2.x CreateEmitter
ends up throwing the exception as an uncaught exception, the 1.x Emitter just returns if the Subscription has already been unsubscribed.
The Wiki at Entering the Reactive World makes it sounds like both should behave the same.
What would be the correct usage in 2.x to get the same behaviour as in 1.x and not crashing the Application with the emitter.onError(...)
call?
Issue Analytics
- State:
- Created 7 years ago
- Comments:19 (13 by maintainers)
Top Results From Across the Web
How to handle dispose in RxJava without InterruptedException
One important design requirement for 2.x is that no Throwable errors should be swallowed. This means errors that can't be emitted because the ......
Read more >RxJava2 UndeliverableException - ProAndroidDev
So in tryOnError() function try to call observer's onError() function if it is not disposed. On the other case it calls RxJavaPlugins.onError ......
Read more >Observable (RxJava Javadoc 2.2.21) - ReactiveX
Unlike the Observable of version 1.x, subscribe(Observer) does not allow external disposal of a subscription and the Observer instance is expected to expose ......
Read more >Using RxJava 2 - Tutorial - Vogella.com
Using RxJava 2 - Tutorial ... 1. Using reactive programming with RxJava 2.0 ... the onError() method is called on each subscriber.
Read more >Master error handling in RxJava. Crush em! - Medium
The chain is disposed of before the Rx calls onError(). ... We see there are 2 ways in which we are throwing an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
See FlowableEmitter.tryOnError and similar methods since 2.1.1 .
Working solution is to manually check if the emitter is not disposed before calling
emitter.onError()
to prevent the throw from happening. Mainly just wanted to point out the difference in Emitters between 1.x and 2.x even though the Wiki states they should be the same