reject parallel new create all node.js promise bluebird

node.js - parallel - promise require('' bluebird '')



Bluebird promisify y devoluciĆ³n de llamada sin argumento de error (1)

Desde Bluebird 2.1 en adelante, ahora puedes personalizar promisifyAll con un manejador de promisificación personalizado:

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. });

Si el método original se ejecuta de forma asincrónica, realmente no hay forma de envolverlo en un dominio, aunque nunca he visto una biblioteca que funcione tan mal.

Estoy tratando de promisificar una biblioteca de terceros que no usa el patrón de callback(err, data) . En su lugar, siempre devuelven la callback(data) y throw errores.

Promise.promisifyAll(horse); var p = Promise.defer(); horse.drinkAsync() .error(function(data) { p.fulfill(data); }) .catch(function (err) { console.error(''error occured'', err); }); return p.promise;

¿Cuál es una buena manera de ajustar ese comportamiento con las promesas y aún así se ve bien y permite detectar el error arrojado? La cláusula catch no se activa y la aplicación falla.