Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 883
mse283 Avatar asked Jan 21 '26 03:01

mse283


1 Answers

use toArray operator is simplier

concat(
  of(1),
  of(4),
  of(7)
).pipe(toArray())
like image 200
Fan Cheung Avatar answered Jan 22 '26 15:01

Fan Cheung