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

Latest commit

 

History

History
79 lines (63 loc) · 2.49 KB

defer.md

File metadata and controls

79 lines (63 loc) · 2.49 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: