I have a this:
new Promise(function (resolve, reject)
{
return Promise.mapSeries(array, function(field)
{
var objCb = {};
var params = {};
objCb.ok = function () {};
objCb.send = function (data)
{
errors.push(data.message);
};
objCb.negociate = function (err)
{
errors.push(data.message);
};
theFunction(params, objCb);
}
}
I have test multiple solutions, but don't work:
return Promise.promisify(theFunction(params, objCb), {multiArgs: true});
and
return Promise.fromCallback(function (objCb)
{
return theFunction(params, objCb);
}, {multiArgs: true}).spread(function (a)
{
console.log("==== 1");
console.log(a);
});
If you have a solution to wait a callback or convert into promise (without edit the function (theFunction)) in a mapSeries, I would be delighted to learn it.
Thanks in advance.
Promise.mapSeries
returns a promise, so you don't need to re-wrap it.
Promise.mapSeries(array, function(field)
{
return new Promise( function(resolve, reject)
{
var objCb = {};
var params = {};
objCb.ok = function (resolve()) {};
objCb.send = function (data)
{
reject(data.message);
};
objCb.negociate = function (err)
{
reject(data.message);
};
theFunction(params, objCb);
}
}
Note: mapSeries
will stop on the first error it encounters.