forked from richardszalay/raix
-
Notifications
You must be signed in to change notification settings - Fork 0
fromAsyncPattern
richardszalay edited this page May 20, 2011
·
8 revisions
Converts a method that returns an AsyncToken into an observable sequence.
static function fromEvent(asyncMethod : Function, args : Array) : IObservable.<*>
Where asyncMethod is function(... args) : AsyncToken
The returned sequence is cold, causing it to execute asyncMethod for each subscriber. To share the subsciption between multiple subscribers, use a sharing operator.
The returned sequence completes after emitting the result value if the AsyncToken calls IResponder.result
The returned sequence emits an error if the returned AsyncToken calls IResponder.fault
token = AsyncToken returned by f(args)
result
token ───────────────────────o
│
output ───────────────────────o/
fault
token ───────────────────────x
│
output ───────────────────────x/
IObservable.<*>
var service : WebService = new WebService();
Observable.fromAsyncToken(service.serviceMethod, [1, 2])
.subscribe(
function(payload : *) : void { trace("Service method returned"); },
function():void { trace("Completed!"); },
function(e:Error):void { trace("Service raised a fault: " + e.message); }
);
// If successful, trace output is:
// Service method returned
// Completed!
// If unsuccessful, trace output is:
// Service raised a fault: <error message>