Created
September 16, 2014 22:04
-
-
Save probablycorey/e831dac67343fc7f70a4 to your computer and use it in GitHub Desktop.
Convert Stream to a ES6 Promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe use
stream.PassThrough?