Wednesday, 15 June 2016

javascript - Promise.all in Node is undefined

I'm playing around with promises in Node.js and am trying to use Promise.all. I'm pushing three functions that return a promise into an array and then calling Promise.all but the all's resolve is never hit. On the debugger, it also says that Promise.all is "undefined".



Why is Promise.all never returning and why does it show up as "undefined"?




Relevant part of the code:



var updates = [];
updates.push(data.updateItemCondition(characterID, specificItemID_toUse, newCondition));
updates.push(data.updateCharacterLoot(characterID, newValue));
updates.push(data.updateSharedLoot(lootUpdateChange));


Promise.all(updates).then(function (success) {
resolve("Item successfully used");

}, function (error) {
resolve("Failed to use item " + error.toString());
});


All three functions look something like the below and using the debugger I can see that all three resolves are hit (and all three corresponding files on io.writeFile are updated on disk)



data.updateSharedLoot= function (lootUpdateChange) {
return new Promise(function (resolve, reject) {
//some logic

io.writeFile(...,function(callbackSuccess){
resolve(callbackSuccess);
});
});
}

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...