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

Retries a source sequence, by resubscribing to it when it errors

function retry(retryCount : uint = 0) : IObservable.<T>

Where retryCount is the number of times to retry (after the first error), or 0 to retry indefinitely.

Remarks

If the source sequence errors, it will be resubscribed to.

The returned sequence completes when the source sequence completes.

The returned sequence errors if the source sequence has been re-subscribed to retryCount number of times and errors. If retryCount is 0, the returned sequence never completes

Marble Diagrams

xs    ──o─────o─────o────x
        │     │     │    └──o─────o─────o────x
        │     │     │       │     │     │    │
ys    ──o─────o─────o───────o─────o─────o────x


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

Return Value

IObservable.<T>

Examples

toObservable(1)
    .concat([Observable.error(new Error("boo"))])
    .retry(1)
    .subscribe(
        function(x : int) : void { trace(x); },
        function():void { trace("Completed"); },
        function(e:Error):void { trace("Retries failed - " + e.message); }
    );

    // Trace output is:
    // 1
    // 1
    // Retries failed - boo
Clone this wiki locally