-
Notifications
You must be signed in to change notification settings - Fork 8
subscribeOn
richardszalay edited this page May 20, 2011
·
6 revisions
Defers subscription to the source through a scheduler
function subscribeOn(scheduler : IScheduler) : IObservable.<T>
The returned sequence completes if the source sequence completes
The returned sequence errors if the source sequence errors
sch = scheduler
xs ┌──o─────o─────/
│ │ │ │
sch ┌──┘ │ │ │
│ │ │ │
zs └─────o─────o─────/
IObservable.<T>
Observable.range(1, 5)
.subscribeOn(Scheduler.asynchronous)
.subscribe(
function(x:int) : void { trace(x); },
function() : void { trace("Completed"); }
);
// The source has no subscriptions yet
// Trace output is:
// (Sometime in the future)
// 1
// 2
// 3
// Completed
In the above example, the values are still emitted from range synchronously, but the initial subscription is delayed until some point in the future by Scheduler.asynchronous.