Skip to content
richardszalay edited this page May 20, 2011 · 9 revisions

Subscribes to multiple source sequences in parallel and emits an array of the last value of sequence after all have completed. The array values will keep the original order of sequences.

static function forkJoin(sources : Array.<IObservable>) : IObservable.<Array>

Remarks

If any sequence completes with no value, the sequence will complete but no values will be emitted.

The returned sequence completes when the all the sequences in sources complete.

The returned sequence raises an error if any of the sequences raises an error.

Marble Diagrams

ws, xs, ys = sources
zs = output

ws ──o──o──o─/
           │
xs ─────o──│─o───/
           │ └───┤
ys ──o─/   └─────┤
     └───────────┤
                 │
zs ──────────────o/

ws ──o──o──o─/

xs ─────o──────x
               │
ys ──o─/       │
               │
zs ────────────x</pre>

Return Value

IObservable.<Array>

Examples

Observable.forkJoin([
        Observable.interval(500).take(2),
        Observable.range(1, 10000, Scheduler.asynchronous)
    ])
    .subscribe(
        function(values : Array) : void { trace(values.join(", ")); },
        function():void { trace("Completed"); }
    );

    // Trace output is:
    // 1, 10000 (after 1 second or the count to 10000 completes, whichever completes last)
    // Completed
Clone this wiki locally