Converts a Promises/A+ spec compliant Promise and/or ES2015 compliant Promise to an Observable sequence.
promise
(Promise): Promises/A+ spec compliant Promise to an Observable sequence.
(Observable
): An Observable sequence which wraps the existing promise success and failure.
// Create a promise which resolves 42
var promise1 = new RSVP.Promise(function (resolve, reject) {
resolve(42);
});
var source1 = Rx.Observable.fromPromise(promise1);
var subscription1 = source1.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Next: 42
// => Completed
// Create a promise which rejects with an error
var promise2 = new RSVP.Promise(function (resolve, reject) {
reject(new Error('reason'));
});
var source2 = Rx.Observable.fromPromise(promise2);
var subscription2 = source2.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Error: Error: reject
File:
Dist:
Prerequisites:
- If using
rx.async.js
|rx.async.compat.js
rx.lite.js
|rx.lite.compat.js
NPM Packages:
NuGet Packages:
Unit Tests: