Created
April 30, 2012 15:18
-
-
Save kconragan/2559176 to your computer and use it in GitHub Desktop.
Generic request handler for returning a promise when requesting a url
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
/* | |
* Internal: Convert the request for a url into a promise | |
* | |
* url - the String to fetch | |
* | |
* Example: return request('http://www.google.com') | |
* | |
* Returns a promise | |
*/ | |
var request = function(url) { | |
// Q-wrapped request function. | |
// Returns request promise. | |
var deferred = Q.defer(); | |
_request(url, function(e, r, b) { | |
if (e) { | |
deferred.reject(new Error(e)); | |
} else { | |
deferred.resolve(b); | |
} | |
}); | |
return deferred.promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment