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

Converts a function into an observable sequence

static function start(action : Function, scheduler : IScheduler = null) : IObservable.<TResult>

Where action is function() : TResult

Remarks

start can be thought of as a callLater equivalent. It is similar to toAsync, but as it accepts no argument the returned sequence can be subscribed to immediately (without calling a function first).

Subscribing to the returned sequence calls the original action and emits the return value of the function as a value and then completes.

If action returns void, the value null will be emitted to the subscriber when the action executes.

Scheduling

Unless specified, Scheduler.asynchronous will be used to schedule the call to action.

Return Value

IObservable.<TResult>

Examples

var asyncAction : Function = Obervable.start(function() : int
    {
        return 500;
    })
    .subscribe(
        function(value : String) : void { trace(value); },
        function():void { trace("Completed"); }
    );

// Trace output is:
// (After the next frame)
// 500
// Completed
Clone this wiki locally