RxJava2.0 - We may need a `Observable.createDisposable(...)`
See original GitHub issueI run into problem when creating Observable with:
Observable.create(new ObservableOnSubscribe())
When new ObservableOnSubscribe
implements Disposable
it is expected to call dispose()
method to release some resources, that is not happening.
Observable
created with Observable.create(..)
doesn’t implement Disposable
and the upstream clean up isn’t passing through to ObservableOnSubscribe
.
I am open to discussion and suggest small change with: Observable.java add method:
public static <T> Observable<T> createDisposable(DisposableObservableOnSubscribe<T> observableOnSubscribe) {
return Observable.create(observableOnSubscribe).doOnDispose(observableOnSubscribe::dispose);
}
with adding new Interface of DisposableObservableOnSubscribe
:
public interface DisposableObservableOnSubscribe<T> extends ObservableOnSubscribe<T>, Disposable {
}
Or doing it other way - like I did on: gist
I didn’t found something that would solve this use case.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
RxJava2: Dispose an Observable chain | by Sachin Chandil
If you are learning RxJava2 or already an experienced developer, you must be ... If there were four Observables, we would need to...
Read more >Modern Android development with Kotlin Part 3 - ProAndroidDev
You can start with RxJava2. Still, it is good for you as an Android developer to know both cause you can be involved...
Read more >When and how to use RxJava Disposable - Cups of Code
They 're meant to give power to the Observers to control Observables . ... While Observable represents a data flow where data can...
Read more >Subscribe Conditionally to rxJava2 Observable - Stack Overflow
For now there is no such method is available in RxJava2. But if you are using kotlin you can do it using extension...
Read more >Observable and Observer - Reactive Programming with RxJava
onNext() can be invoked zero, one, or multiple times by the Observable whereas ... Looking at the Observable and Observer definitions, we can...
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
Here’s a simpler implementation:
It worked like a charm, thank you Jake.