Skip to content

Instantly share code, notes, and snippets.

@Yardanico Yardanico/scheduling.nim
Last active May 6, 2018

What would you like to do?
import asyncdispatch
template scheduleCall(ms: int, oneshot: bool, call: untyped) =
# We use `block` here because we can't use gensym with async
proc sched() {.async.} =
await sleepAsync(ms)
await call
if not oneshot:
# We don't use await here because otherwise every sched() call
# will be included in possible stack traces
asyncCheck sched()
asyncCheck sched()
proc mydata(data: string) {.async.} =
echo "Mydata called with " & data
proc main {.async.} =
echo "Scheduling it..."
scheduleCall(250, false, mydata("250"))
scheduleCall(500, false, mydata("500"))
scheduleCall(750, false, mydata("750"))
scheduleCall(1000, false, mydata("1000"))
scheduleCall(1250, false, mydata("1250"))
scheduleCall(1500, false, mydata("1500"))
echo "Not blocking!"
asyncCheck main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.