Skip to content

Instantly share code, notes, and snippets.

@kconragan
Created April 30, 2012 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kconragan/2559176 to your computer and use it in GitHub Desktop.
Save kconragan/2559176 to your computer and use it in GitHub Desktop.
Generic request handler for returning a promise when requesting a url
/*
* 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