Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
master
Go to file
#1503)

There has been a LOT of confusion by RxJS users when they find the RxJS v4 docs and not v5 docs. This is to get rid of that confusion. Also updated the readme to no longer say v5 is beta, v6 will be beta pretty soon. ;)
7 contributors

Users who have contributed to this file

@mattpodwysocki @L8D @mmv @j4ckcyw @deerawan @davidwdan @benlesh
94 lines (73 sloc) 3.15 KB

This is RxJS v 4. Find the latest version here

Rx.Observable.fromPromise(promise)

Converts a Promises/A+ spec compliant Promise and/or ES2015 compliant Promise or a factory function which returns said Promise to an Observable sequence.

Arguments

  1. promise|Function: Promise - Promises/A+ spec compliant Promise to an Observable sequence or a function which returns a Promise.

Returns

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

Example

// Create a factory function which returns a promise
var promiseFn = function () { return Promise.resolve(42); };

var source = Rx.Observable.fromPromise(promiseFn);

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// Create a promise which resolves 42
var promise1 = Promise.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 = Promise.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:

You can’t perform that action at this time.