-
Notifications
You must be signed in to change notification settings - Fork 8
toAsync
richardszalay edited this page May 20, 2011
·
8 revisions
Converts a function into an observable sequence that will accept its arguments at a later time.
static function toAsync(action : Function, scheduler : IScheduler = null) : Function
Where action is function(... any) : TResult
toAsync can be thought of as a callLater equivalent, except the return value of the function is accessible.
The return value accepts the same arguments as action but returns an observable sequence (of valueClass) that can be subscribed to. Subscribing to the returned sequence calls the original action with the argument specified and emits the return value of the function as a value and then completes.
Unless specified, Scheduler.asynchronous
will be used to schedule the call to action.
function(... args) : IObservable.<TResult>
var asyncAction : Function = Obervable.toAsync(function(x : int) : int
{
return x * 2;
});
var callWithFive : IObservable = asyncAction(5);
callWithFive.subscribe(
function(value : String) : void { trace(value); },
function():void { trace("Completed"); }
);
// Trace output is:
// (After the next frame)
// 10
// Completed