Reputation: 461
let array = []
for (let n = 0; n < 1000; n++){
array.push(somePromise)
}
console.log(array.length)
How to modify the code, so that in line where I have console.log will be executed only after the array is filled. Filling might be async, but I am interrested in sync version as well.
Upvotes: 1
Views: 39
Reputation: 2849
Actually, filling is sync. Do you mean Promise.all()
? Using Promise.all
, you can handle some after all promises are completed.
let array = []
for (let n = 0; n < 1000; n++){
array.push(somePromise)
}
Promise.all(array)
.then((res) => {
// You can handle some here
console.log(res);
})
Upvotes: 1