Skip to content

Instantly share code, notes, and snippets.

@spion

spion/pipe-promises.js

Forked from domenic/pipe-promises.js
Last active Aug 29, 2015
Embed
What would you like to do?
exports.pipe = function (source, sink) {
var resolve, reject;
return new Promise(function(resolve_, reject_) {
resolve = resolve_;
reject = reject_;
source
.on("error", reject)
.pipe(sink)
.on("error", reject);
.on("finish", resolve);
}).finally(function() {
source.removeListener("error", reject);
sink.removeListener("error", reject);
sink.removeListener("finish", resolve);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment