Skip to content

Instantly share code, notes, and snippets.

@x86128
Created October 18, 2017 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x86128/ca24c941d7deb25294fbb3e7b254dacf to your computer and use it in GitHub Desktop.
Save x86128/ca24c941d7deb25294fbb3e7b254dacf to your computer and use it in GitHub Desktop.
Async probes
import asyncdispatch
import httpclient
import os
proc task(i: int): Future[void] {.async.} =
echo("Started: " & $i)
await sleepAsync(i*1000+500)
echo("Ended: " & $i)
proc main() {.async.} =
var ft = newseq[Future[void]]()
for i in countdown(10,1):
ft.add task(i)
echo("Done placing!")
for i in ft:
await i
echo("Done waiting!")
asyncCheck main()
while hasPendingOperations():
poll()
sleep(10)
import asyncdispatch
import httpclient
proc task(i: int): Future[void] {.async.} =
echo("Started: " & $i)
await sleepAsync(i*1000+500)
echo("Ended: " & $i)
proc main() {.async.} =
var ft = newseq[Future[void]]()
for i in countdown(10,1):
ft.add task(i)
echo("Done placing!")
for i in ft:
await i
echo("Done waiting!")
waitFor main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment