Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pipe with promises
exports.pipe = function (source, sink) {
var deferred = Q.defer();
source
.on("end", deferred.resolve)
.on("error", deferred.reject)
.pipe(sink)
.on("error", deferred.reject);
deferred.promise.finally(function () {
source.removeListener("end", deferred.resolve);
source.removeListener("error", deferred.reject);
sink.removeListener("error", deferred.reject);
});
return deferred.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment