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

Takes values from a source sequence until a value is received from another sequence

function takeUntil(other : IObservable.<*>) : IObservable.<T>

Remarks

other is also subscribed to. The values in the source sequence are emitted until other emits a value, at which time other is unsubscribed from and the sequence completes.

The returned sequence completes when the source sequence completes or when other emits a value.

The returned sequence errors when the source sequence errors or when the other sequence errors.

Marble Diagrams

xs = source
ys = output

other ──────────o
xs    ──o──o──o─│
        │  │  │ │
        │  │  │ │
        │  │  │ │
ys    ──o──o──o─/

other ──────────────────
xs    ──o──o──o──o──o──/
        │  │  │  │  │  │
        │  │  │  │  │  │
        │  │  │  │  │  │
ys    ──o──o──o──o──o──/

Return Value

IObservable.<T>

Examples

var source : IObservable = Observable.interval(500)
    .takeUntil( Observable.interval(2001) );

source.subscribe(
    function(value : int) : void { trace(value); },
    function() : void { trace("Completed!"); }
    );

// Trace output is:
// 0 (at 500 ms)
// 1 (at 1000 ms)
// 2 (at 1500 ms)
// 3 (at 2000 ms)
// Completed!