I'm using kriskowal/q
promise library to handle http requests, but to simplify the case, let's assume I have an array of promises created dynamically and pushed to the promises
array:
var promises = [],
ids = ['foo', 'bar', 'buz'];
ids.forEach(function(id){
var promise = Q.fcall(function () {
return 'greetings with ' + id;
});
promises.push(promise);
});
// and handle all of them together:
Q.all(promises).then(function (results) {
console.log(results);
});
// gives:
[ 'greetings with foo',
'greetings with bar',
'greetings with buz' ]
The question is - is it possible to assign somehow an id
to the promise to obtain it later in all
execution ?
Let's assume that we cannot modify the returned value (it comes from the API and I cannot extend it with extra data).