1.0.0 • Published 4 years ago

promising-a-stream v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

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');