UNPKG

@reactivex/rxjs

Version:

Reactive Extensions for modern JavaScript

25 lines 696 B
import { root } from '../util/root'; /** * @param PromiseCtor * @return {Promise<T>} * @method toPromise * @owner Observable */ export function toPromise(PromiseCtor) { if (!PromiseCtor) { if (root.Rx && root.Rx.config && root.Rx.config.Promise) { PromiseCtor = root.Rx.config.Promise; } else if (root.Promise) { PromiseCtor = root.Promise; } } if (!PromiseCtor) { throw new Error('no Promise impl found'); } return new PromiseCtor((resolve, reject) => { let value; this.subscribe((x) => value = x, (err) => reject(err), () => resolve(value)); }); } //# sourceMappingURL=toPromise.js.map