forkJoin<T, R> method

Observable<R> forkJoin<T, R>(
  1. Iterable<Stream<T>> streams,
  2. R combiner(
    1. List<T> values

Creates an Observable where all last events of existing stream(s) are piped through a sink-transformation.

This operator is best used when you have a group of observables and only care about the final emitted value of each. One common use case for this is if you wish to issue multiple requests on page load (or some other event) and only want to take action when a response has been received for all.

In this way it is similar to how you might use Future.wait.

Be aware that if any of the inner observables supplied to forkJoin error you will lose the value of any other observables that would or have already completed if you do not catch the error correctly on the inner observable.

If you are only concerned with all inner observables completing successfully you can catch the error on the outside. It's also worth noting that if you have an observable that emits more than one item, and you are concerned with the previous emissions forkJoin is not the correct choice.

In these cases you may better off with an operator like combineLatest or zip.


Observable.forkJoin([ new Observable.just("a"), new Observable.fromIterable("b", "c", "d") ], (list) => list.join(', ')) .listen(print); // prints "a, d"


static Observable<R> forkJoin<T, R>(
        Iterable<Stream<T>> streams, R combiner(List<T> values)) =>
    Observable<R>(ForkJoinStream<T, R>(streams, combiner));