From Bluebird 2.1 on, you can now configure promisifyAll using the special promisification handler:
function noErrPromisifier(originalMethod){ return function promisified() { var args = [].slice.call(arguments); // might want to use smarter var self = this // promisification if performance critical return new Promise(function(resolve,reject){ args.push(resolve); originalMethod.apply(self,args); // call with arguments }); }; } var horse = Promise.promisifyAll(require("horse"), { promisifier: noErrPromisifier }); horse.drinkAsync().then(function(data){ // Can use here, ow promisified normally. });
If the original method is thrown asynchronously, there really is no way to wrap it in a domain, although I have never seen a library that works poorly.
Benjamin gruenbaum
source share