This is RxJS v 4. Find the latest version here
Converts an Observable sequence to a ES2015 compliant promise.
[promiseCtor]
(Promise): An ES2015 compliant Promise that can be created. This is optional. If your runtime already supports ES2015 promises, you do not need to fill in this parameter. Alternatively you can specify an ES2015 complaint promise viaRx.config.Promise
(Promise
): An ES2015 compliant promise which contains the last value from the Observable sequence. If the Observable sequence is in error, then the Promise will be in the rejected stage. If the sequence is empty, the Promise will not resolve.
/* Using normal ES2015 */
let source = Rx.Observable
.just(42)
.toPromise();
source.then((value) => console.log('Value: %s', value));
// => Value: 42
/* Rejected Promise */
/* Using normal ES2015 */
let source = Rx.Observable
.throw(new Error('woops'))
.toPromise();
source
.then((value) => console.log('Value: %s', value))
.catch((err) => console.log('Error: %s', err));
// => Error: Error: woops
/* Setting via the config */
Rx.config.Promise = RSVP.Promise;
let source = Rx.Observable
.just(42)
.toPromise();
source.then((value) => console.log('Value: %s', value));
// => Value: 42
/* Setting via the method */
let source = Rx.Observable
.just(42)
.toPromise(RSVP.Promise);
source.then((value) => console.log('Value: %s', value));
// => Value: 42
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: