Skip to content

Instantly share code, notes, and snippets.

@jcready
Created May 4, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcready/f9b288a0044985c31b436b7c394fa1c4 to your computer and use it in GitHub Desktop.
Save jcready/f9b288a0044985c31b436b7c394fa1c4 to your computer and use it in GitHub Desktop.
(function(){
const EE = require('events')
const Stream = require('stream')
const promise = Symbol('StreamPromise')
Stream.prototype.constructor = function () {
EE.call(this)
this[promise] = new Promise((resolve, reject) => {
this.on('error', reject)
this.on('end', resolve)
this.on('finish', resolve)
})
}
Stream.prototype.then = function (yay, nay) {
return this[promise].then(yay, nay)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment