Created
October 18, 2017 05:40
-
-
Save x86128/ca24c941d7deb25294fbb3e7b254dacf to your computer and use it in GitHub Desktop.
Async probes
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 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) |
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 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