Skip to content

Latest commit

 

History

History
78 lines (62 loc) · 2.41 KB

defer.md

File metadata and controls

78 lines (62 loc) · 2.41 KB

Rx.Observable.defer(observableFactory)

Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.

Arguments

  1. observableFactory (Function): Observable factory function to invoke for each observer that subscribes to the resulting sequence.

Returns

(Observable): An observable sequence whose observers trigger an invocation of the given observable factory function.

Example

/* Using an observable sequence */
var source = Rx.Observable.defer(function () {
    return Rx.Observable.return(42);
});

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

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

/* Using a promise */
var source = Rx.Observable.defer(function () {
    return RSVP.Promise.resolve(42);
});

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: