mse283
mse283

Reputation: 33

Subscribe to all observables sequentially, and then emit values as array once all have completed

I'm looking to make several sequential requests to a server. I need each of the requests to start as the previous request completes and then, once all of them have completed, emit the values as an array.

I've tried using zip and forkJoin, but these subscribe to all the observables in parallel. concat is almost there, but it emits as each of the observables completes, whereas I need it to hold off emitting until all observables have completed and then emit all the values as an array.

Upvotes: 3

Views: 493

Answers (1)

Fan Cheung
Fan Cheung

Reputation: 11345

use toArray operator is simplier

concat(
  of(1),
  of(4),
  of(7)
).pipe(toArray())

Upvotes: 5

Related Questions