I am using the got package and trying to send a GET request to check items in an array. This request is looped for each item in the array and then these items are further sorted into more arrays, the rest of the code depends on this list. Afterwards one of these arrays will be sent to another server for DELETE requests.
The structure is as follows:
for (let i in arrTags){
const {body} = await got(`https://example.com/path/to/${i}`)
if (body.length > 0 &&
// find current revision (Git SHA) to compare with i
body.current_revision.substring(0, tag.length) !== i) {
arrTagsToDelete.push(tag)
} else {
arrTagsIgnored.push(tag)
}
}
later on in the code we delete items in arrTagsToDelete:
for (let i in arrTagsToDelete){
await got.delete(`https://anotherwebsite.com/path/to/${i}`, {username: args.username, password: args.password}) //using oclif we get auth
}
I am getting an issue with ESLint telling me I cannot use Async-await inside a for-loop, I know I cannot use a forEach since async-await does not play nicely according to other answers on StackOverflow,it will run the rest of the code before the GET request and DELETE requests are done. I have seen as well that disabling ESLint warnings for this scenario isn't uncommon.
I would prefer to maybe have a cleaner solution to this problem than disabling the ESLint, unless that is the only way.
Thank you in advance.
Promise.allto do all requests concurrently instead of sequentially e.g.await Promise.all(arrTagsToDelete.map((value, i) => got.delete(...))might workfor into afor of?