Promote a list of elements in an array
I cannot find examples showing how you are going to use promises with a list (array, in this case or others ...). For example, I have a list:
var list = [1, 2, 3, 4, 5];
And I would like to perform the operation, and once they are fully (resolved), pass the results to another function. I am using a lazy approach, but is there a cleaner solution?
Promise
.map(result, function(number) {
var defer = Promise.pending();
setTimeout(function() {
return defer.resolve(number * 2);
}, 2000);
return defer.promise;
})
.then(function(result) {
console.log(result);
});
Thanks in advance for your help.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: