-
-
Save kriskowal/2126149 to your computer and use it in GitHub Desktop.
Streams are painful
This file contains 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
function promiseResponse(request) { | |
var deferred = Q.defer(); | |
request.on("error", deferred.reject); | |
request.on("response", deferred.resolve); | |
return deferred.promise | |
// if you must: | |
.fin(function () { | |
request.removeListener("error", deferred.reject); | |
request.removeListener("response", deferred.resolve); | |
}); | |
} | |
function exists(id) { | |
return promiseResponse(knoxClient.head(id)) | |
.then(function (response) { | |
return response.statusCode === 200; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment