I am working on a tool that scrapes the content of a sitemap.
I have an async procedure getEntries that I call for each sitemap entry in a sitemap index.
In my current code I await the result of each call to getEntries, code below.
for sitemapIndexEntry in getSitemapIndexEntries(sitemapContent):
await getEntries(sitemapIndexEntry.loc)
Is there a way that instead of waiting for each call, I could add the call to a sequence and await the completion of all calls. This would allow for the requests to run in parallel, instead of one at a time.
Basically the equivalent of Promise.all in JavaScript.
Please let me know if there is a more dogmatic approach to the one I have described.
You can add all the futures to a sequence and then call all on it like
var futs: seq[Future[Something]]
for sitemapIndexEntry in getSitemapIndexEntries(sitemapContent):
futs &= getEntries(sitemapIndexEntry.loc)
let entries = await futs.all()
@amadan & @PMunch
That is exactly what I was looking for. Thank you.