wallet-core/node_modules/observable-to-promise/index.js
2017-05-28 00:40:43 +02:00

24 lines
445 B
JavaScript

'use strict';
const isObservable = require('is-observable');
const symbolObservable = require('symbol-observable').default;
module.exports = val => {
if (!isObservable(val)) {
throw new TypeError('Expected an Observable');
}
const ret = [];
return new Promise((resolve, reject) => {
val[symbolObservable]().subscribe({
next: x => {
ret.push(x);
},
error: reject,
complete: () => {
resolve(ret);
}
});
});
};