fromAsyncPattern
richardszalay edited this page Sep 14, 2010
·
8 revisions
Converts a method that returns an AsyncToken into an observable sequence.
static function fromEvent(valueClass : Class, asyncMethod : Function, args : Array) : IObservable.<valueClass>
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.<valueClass>
var service : WebService = new WebService();
Observable.fromAsyncToken(PayloadType, service.serviceMethod, [1, 2])
.subscribe(
function(payload : PayloadType) : 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>