-
Notifications
You must be signed in to change notification settings - Fork 8
defer
richardszalay edited this page May 20, 2011
·
7 revisions
Defers selection of a sequence until the sequence is subscribed to
static function defer(observableFactory:Function) : IObservable.<TResult>
Where observableFactory is function () : IObservable.<TResult>
The returned sequence completes if the source sequence completes
The returned sequence errors if the source sequence errors or if func throws an error
xs ─┐
f()
└───o─────o──/
│ │ │
zs ─────o─────o──/
IObservable.<TResult>
var toggle : Boolean = false;
var source : IObservable = Observable.defer(function() : IObservable
{
toggle = !toggle;
return (toggle)
? Observable.value(50)
: Observable.value(100);
});
var observer : IObserver = Observer.create(
function(x:int) : void { trace(x); },
function() : void { trace("Completed"); }
);
source.subscribeWith(observer);
source.subscribeWith(observer);
source.subscribeWith(observer);
// Trace output is:
// 50
// Completed
// 100
// Completed
// 50
// Completed