PGuertler
PGuertler

Reputation: 243

Single.zip with Completable

Here is my question: I have some singles and want to zip them. But I only want the zip function to be called after a Completable has completed. Also I want to subscribe to all singles and the Completable at the same time. (So no completable.andThen(Single.zip(...))

Here is an example of what I'm doing now:

Single<T1> s1 = …;
Single<T2> s2 = …;
Single<T3> s3 = …;
Completable c = …;

Single.zip(s1, s2, s3, c.andThen(Single.just("")), (a, b, c, ignore) -> {
// All singles have emitted an item and c is completed
 …
})

Is there a better way?

Upvotes: 8

Views: 13308

Answers (1)

akarnokd
akarnokd

Reputation: 70007

You could use toSingleDefault when converting from Completable to Single:

Single<T1> s1 = …;
Single<T2> s2 = …;
Single<T3> s3 = …;
Completable c = …;

Single.zip(s1, s2, s3, c.toSingleDefault(""), (a, b, c, ignore) -> {
// All singles have emitted an item and c is completed
…
})

Upvotes: 18

Related Questions