Skip to content

Instantly share code, notes, and snippets.

@esamattis
Created April 23, 2014 10:13
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esamattis/11209665 to your computer and use it in GitHub Desktop.
Save esamattis/11209665 to your computer and use it in GitHub Desktop.
var Promise = require("bluebird");
var Request = require("superagent").Request;
/**
* @namespace utils
* @class Superagent
*/
/**
*
* Add promise support for superagent/supertest
*
* Call .promise() to return promise for the request
*
* @method promise
* @return {Bluebird.Promise}
*/
Request.prototype.promise = function() {
var self = this;
return new Promise(function(resolve, reject){
Request.prototype.end.call(self, function(err, res) {
if (err) reject(err);
else resolve(res);
});
});
};
@KyleAMathews
Copy link

I borrowed this and published in to NPM :) Thanks!

https://www.npmjs.org/package/superagent-bluebird-promise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment