Convert an Observable stream to Completable
See original GitHub issueIf I’m not mistaken, Completable is supposed to be a replacement for things like Observable<Void>
, but it seems like combining them with Observables is messier.
It’s possible I’m doing something weird here, but this is what I want to do:
Given
Observable<Data> makeHttpCall();
Completable storeInDatabase(Data data);
Ideally I would be able to do something like this:
Completable syncData() {
return makeHttpCall().flatMap(storeInDatabase);
}
But currently this is what I have:
Completable syncData() {
return makeHttpCall()
.flatMap(data -> storeInDatabase(data).toObservable<Void>())
.toCompletable();
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
How to convert rxJava2's Observable to Completable?
The fluent way is to use Observable.ignoreElements() . Observable.just(1, 2, 3) .ignoreElements(). Convert it back via toObservable if needed.
Read more >Converting between Completablefuture and Observable
CompletableFuture represents one value in the future, so turning it into Observable is rather simple. When Future completes with some value, ...
Read more >Bridging CompleteableFutures and RxJava | by Brian Schlining
Here's a method that takes a collection of items and a function that will convert an item to a CompleteableFuture, then returns an...
Read more >From RxJava to Kotlin Flow: Stream Types - ProAndroidDev
If we try to compare RxJava stream types with what we have in Kotlin, we get the following: Observable/Flowable are represented via Flow....
Read more >Converting RxJava Observables to Java 8 Completable future ...
We extend CompletableFuture and then we just subscribe to the observable. Subscribe method accepts two actions. The first will be called when 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
You can do this with some conversions:
It looks like
Completable.merge
solves my issue of transformingObservable<Completable>
toCompletable
then. Thanks!