promising-a-stream
v1.0.0
Published
listen stream to be ready and return a promise what is resolved with success and rejected with error event
Downloads
2
Readme
stream-to-promise
listen the error and success event to resolve and reject promise
API
streamToPromise(StreamInstance, successString) -> PromiseInstance
Receive a stream and listen the success and error event to resolve and reject the promise returned.
Example
const assert = require('assert');
const EventEmitter = require('events');
const streamToPromise = require('stream-to-promise');
const emitter = new EventEmitter();
setTimeout(() => emitter.emit('successString', 'res'), 1000);
const res = await streamToPromise(emitter, 'successString');
assert(res == 'res');