Created
April 23, 2014 10:13
-
-
Save esamattis/11209665 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I borrowed this and published in to NPM :) Thanks!
https://www.npmjs.org/package/superagent-bluebird-promise