question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Convert an Observable stream to Completable

See original GitHub issue

If 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:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
akarnokdcommented, Mar 29, 2016

You can do this with some conversions:

Completable.merge(makeHttpCall().map(v -> storeInDatabase(v).toCompletable())).await();
0reactions
jmmkcommented, Mar 30, 2016

It looks like Completable.merge solves my issue of transforming Observable<Completable> to Completable then. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found