DEV Community


Promise.all alternative in RxJS

sainig profile image Gaurav Saini ・1 min read

I'm a bit late to the party but I finally took out the time to learn RxJS and already in love with it ❤️.

What I did

I was wondering, there has to be something like Promise.all in RxJS and here's what I came up with

import { ajax } from 'rxjs/ajax';
import { of } from 'rxjs';

const myObs = of([
// now myObs is of the type Observable<Observable<AjaxResponse>[]>
// for some reason I don't feel too good about this

myObs.subscribe(function(value) {
   * here I get an array of 2 observables which I have to
   * loop over and subscribe to each of the observables
  console.log('emitted value:', value);

What I need

So, my question is, is there any better way of doing what I'm trying to do?
Thanks a lot in advance!

Discussion (4)

Editor guide
glebirovich profile image
Gleb Irovich

combineLatest has a very similar signature

kelvinmai profile image
Kelvin Mai

What you want is forkJoin

gktim profile image
gkTim • Edited

You can use for forkJoin for this

sainig profile image
Gaurav Saini Author

Thanks, that’s exactly what I needed 👍