Skip to content

Latest commit

 

History

History
82 lines (63 loc) · 2.71 KB

frompromise.md

File metadata and controls

82 lines (63 loc) · 2.71 KB

Rx.Observable.fromPromise(promise)

Converts a Promises/A+ spec compliant Promise and/or ES2015 compliant Promise to an Observable sequence.

Arguments

  1. promise (Promise): Promises/A+ spec compliant Promise to an Observable sequence.

Returns

(Observable): An Observable sequence which wraps the existing promise success and failure.

Example

// 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

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: