Skip to content

Instantly share code, notes, and snippets.

@cabhishek
Last active December 8, 2017 16:26
Show Gist options
  • Save cabhishek/cc20ea8b422f7506256af15a49dfe165 to your computer and use it in GitHub Desktop.
Save cabhishek/cc20ea8b422f7506256af15a49dfe165 to your computer and use it in GitHub Desktop.
Async http in Nim
import os, strutils, asyncdispatch, httpclient
const baseUrl = "http://jsonplaceholder.typicode.com"
proc doRequest(url: string): Future[string] =
echo "Fetching contents from $1" % url
result = newAsyncHttpClient().getContent(url)
proc main() {.async.} =
var requests: seq[Future[string]] = @[]
for resource in @["posts", "comments", "albums"]:
requests.add(doRequest(baseUrl / resource)) # How long does it take for every doRequest to complete??
echo await all(requests)
waitFor main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment