Last active
December 8, 2017 16:26
-
-
Save cabhishek/cc20ea8b422f7506256af15a49dfe165 to your computer and use it in GitHub Desktop.
Async http in Nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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