wallet-core/node_modules/observable-to-promise/index.js

24 lines
445 B
JavaScript
Raw Normal View History

2017-05-28 00:38:50 +02:00
'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);
}
});
});
};