Skip to content

Instantly share code, notes, and snippets.

@lanceharper
Last active August 29, 2015 14:05
Show Gist options
  • Save lanceharper/29368355cd4871fcaf00 to your computer and use it in GitHub Desktop.
Save lanceharper/29368355cd4871fcaf00 to your computer and use it in GitHub Desktop.
pipe with bluebird
var Promise = require("bluebird");
exports.pipe = function (source, sink) {
var resolve, reject;
return new Promise(function(resolve_, reject_) {
resolve = resolve_;
reject = reject_;
source
.on("end", resolve)
.on("error", reject)
.pipe(sink)
.on("error", reject);
}).finally(function() {
console.log('finally');
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