I tested Bluebird for the first time with Mongoose method calls. It was very easy, just had to do something like Promise.promisifyAll(myObj)
and then call myObj.methodAsync
But when I tried to implement it without Mongoose, I didn't know what to do, for example:
function Foo(){}
Foo.prototype.test = function(c,cb){
cb(new Error(),{a:1, b:2, c:c});
};
module.exports = new Foo();
This throws this error in then
.
Unhandled rejection (<{"a":1,"b":2,"c":true}>, no stack trace).
This is going to catch
, and there I can use it without errors.
Anyone knows how to implement my method to work well with a promise implementation?
Your call back is returning new Error()
, just use cb(null, {a:1, b:2,c:c});