This is RxJS v 4. Find the latest version here
Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
observableFactory
(Function
): Observable factory function to invoke for each observer that subscribes to the resulting sequence.
(Observable
): An observable sequence whose observers trigger an invocation of the given observable factory function.
/* 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
File:
Dist:
Prerequisites:
- None
NPM Packages:
NuGet Packages:
Unit Tests: