Question

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

Was it helpful?

Solution

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
    );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top