I have an async await function that is processing items out of order in a loop. How do i check each item in the array before done! logs to console? So each time the link errors out, it should log the error after the index number it associates with. For example:
0
ERROR HERE https://test123.com/ergaergrhaerha0
1
2
3
ERROR HERE https://test123.com/ergaergrhaerha3
...
done!
processArray(ftJsonBySeqAssets);
async function processArray(arr) {
for (i in arr) {
console.log(i)
await https.get(arr[i].image_link, async (res) => {
await console.log(res.statusCode, arr[i].image_link)
if (res.statusCode === 404) {
console.log('ERROR HERE', arr[i].image_link)
audience.error.image_link.push(arr[i].image_link)
audience.error.count++
}
});
await https.get(arr[i].link, async (res) => {
await console.log(res.statusCode, arr[i].link)
if (res.statusCode === 404) {
console.log('ERROR HERE', arr[i].link)
audience.error.link.push(arr[i].link)
audience.error.count++
}
});
}
console.log('done!')
}
Logs:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
done!
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1
ERROR HERE https://test123.com/ergaergrhaerha1