import strutils, sequtils, os, strformat, httpclient, asyncdispatch
# const links: seq[string] = # omitted
const dir = "dir"
os.createDir(fmt"{os.getCurrentDir()}/{dir}")
proc download(link: string; i: int): Future[void] {.async.} =
var fileName = fmt"{os.getCurrentDir()}/{dir}/{i}.webm"
var client = newAsyncHttpClient()
echo(fmt"Downloading {filename}...")
await downloadFile(client, link, fileName)
echo(fmt"Downloading {filename} success.")
proc main() {.async.} =
for i, link in links:
await download(link, i)
waitFor main()
Run
I have moved my `download` logic to an async function and called `await` on the
callsites of the `download` function. I `waitFor` the calle (`main`) which is
also an async function. Yet I keep getting sequential downloads of `links`. I
want to download the fils asynchronously. How should I proceed?