Reputation: 3554
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
Upvotes: 2
Views: 1572
Reputation: 3554
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
);
Upvotes: 1