Skip to content
richardszalay edited this page May 20, 2011 · 6 revisions

Defers subscription to the source through a scheduler

function subscribeOn(scheduler : IScheduler) : IObservable.<T>

Remarks

The returned sequence completes if the source sequence completes

The returned sequence errors if the source sequence errors

Marble Diagrams

sch = scheduler

xs     ┌──o─────o─────/
       │  │     │     │
sch ┌──┘  │     │     │
    │     │     │     │
zs  └─────o─────o─────/

Return Value

IObservable.<T>

Examples

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.

Clone this wiki locally