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

Executes a function when the sequence completes or errors.

function finallyAction(action : Function) : IObservable.<T>

Where action is function () : void

Remarks

The returned sequence completes if the source sequence completes

The returned sequence errors if the source sequence errors or if finallyAction throws an error

Marble Diagrams

f() = finallyAction

xs ──o─────o─────/
                 ├f()
zs ──o─────o─────/

xs ──o─────o─────x
                 ├f()
zs ──o─────o─────x

Return Value

IObservable.<T>

Examples

Observable.value(1)
    .finallyAction(
        function():void { trace("Finally!"); }
    )
    .subscribe(
        function(x:int) : void { trace(x); },
        function() : void { trace("Completed"); },
        function(e:Error) : void { trace("Error: " + e.message); }
    );

    // Trace output is:
    // 1
    // Finally!
    // Completed
Observable.error(new Error("Boo!"))
    .finallyAction(
        function():void { trace("Finally!"); }
    )
    .subscribe(
        function(x:int) : void { trace(x); },
        function() : void { trace("Completed"); },
        function(e:Error) : void { trace("Error: " + e.message); }
    );

    // Trace output is:
    // Finally!
    // Error: Boo!