Skip to content

Instantly share code, notes, and snippets.

@probablycorey
Created September 16, 2014 22:04
Show Gist options
  • Save probablycorey/e831dac67343fc7f70a4 to your computer and use it in GitHub Desktop.
Save probablycorey/e831dac67343fc7f70a4 to your computer and use it in GitHub Desktop.
Convert Stream to a ES6 Promise
stream = require 'stream'
class ToPromise extends stream.Writable
constructor: ->
@promise = new Promise (resolve, reject) =>
@on 'finish', resolve
@on 'error', reject
super(objectMode: true)
then: (success, failure) ->
@promise.then(success, failure)
catch: (failure) ->
@promise.catch(failure)
module.exports = -> new ToPromise()
@probablycorey
Copy link
Author

Maybe use stream.PassThrough?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment