2

I'm attempting to do some async work on n items, and wait for all items to complete before proceeding.

What do I put in the whatfunc? location to have subscribe's onComplete fire once?

Observable.range(0, n)
    .<whatfunc?>({ s ->  doAsyncWorkThatReturnsObservable(s) })
    .(other?)
    .subscribe({println "All complete"})

Thanks

1 Answer 1

1

flatMap

Be sure to provide closures to the correct arguments in subscribe. Example from link adjusted to fit your provided example:

Observable.range(0, n)
    .flatMap({n -> doAsyncWorkThatReturnsObservable(n)})
    .subscribe(
       { println(it); },                          // onNext
       { println("Error: " + it.getMessage()); }, // onError
       { println("Sequence complete"); }          // onCompleted
    );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.