forkJoin<T, R> method

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

Creates a Stream 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 streams 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 streams supplied to forkJoin error you will lose the value of any other streams that would or have already completed if you do not catch the error correctly on the inner stream.

If you are only concerned with all inner streams completing successfully you can catch the error on the outside. It's also worth noting that if you have an stream 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.

If the provided streams is empty, the resulting sequence completes immediately without emitting any items and without any calls to the combiner function.


Rx.forkJoin([ Stream.value('a'), Stream.fromIterable('b', 'c', 'd') ], (list) => list.join(', ')) .listen(print); // prints 'a, d'


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