Skip to content
richardszalay edited this page May 20, 2011 · 1 revision

Convience method for creating IObservable sequences

global function toObservable(... args) : IObservable.<*>

toObservable can be considered to have the following overloads:

Signature Equivalent
function toObservable() Observable.empty()
function toObservable(enumerable : IEnumerable) enumerable.toObservable()
function toObservable(array : Array) Observable.fromArray(array)
function toObservable(observable : IObservable) observable
function toObservable(error : Error) Observable.error(error)
function toObservable(value : *) Observable.value(value)

Examples

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

    // Trace output is:
    // 5
    // Completed!
toObservable([1, 2, 3, 4, 5])
    .subscribe(
        function(value:int) : void { trace(value); },
        function():void { trace("Completed!"); }
     );

    // Trace output is:
    // 1
    // 2
    // 3
    // 4
    // 5
    // Completed!
Clone this wiki locally