Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Latest commit

 

History

History
72 lines (55 loc) · 2.31 KB

subscribeon.md

File metadata and controls

72 lines (55 loc) · 2.31 KB

Rx.Observable.prototype.subscribeOn(scheduler)

Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler.

This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer callbacks on a scheduler, use observeOn.

Arguments

  1. scheduler (Scheduler): Scheduler to notify observers on.

Returns

(Observable): The source sequence whose observations happen on the specified scheduler.

Example

var observable = Rx.Observable.create(function (observer) {
    function handler () {
        observer.onNext(42);
        observer.onCompleted();
    }

    // Change scheduler for here
    var id = setTimeout(handler, 1000);

    return function () {
        // And change scheduler for here
        if (id) clearTimeout(id);
    };
});

// Change the scheduler to timeout for subscribe/unsubscribe
var source = observable.subscribeOn(Rx.Scheduler.timeout);

var subscription = source.subscribe(
    function (x) {
        console.log('Next: ' + x);
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    });

// => Next: 42
// => Completed

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests: