Skip to content

Instantly share code, notes, and snippets.

@Varriount
Last active June 19, 2016 18:16
Show Gist options
  • Save Varriount/94eb49206bd6268e48d042b4c1f63108 to your computer and use it in GitHub Desktop.
Save Varriount/94eb49206bd6268e48d042b4c1f63108 to your computer and use it in GitHub Desktop.
import asyncdispatch
# See http://nim-lang.org/docs/manual.html#templates-typed-vs-untyped-parameters
# for information on typed vs untyped parameters
template doAsync(name, body: untyped): untyped =
# Backticks allow us to use an expression or statement as an identifier
proc `name`() {.async.} =
body
asyncCheck(`name`())
template doAsync(body: untyped): untyped =
proc asyncproc() {.async.} =
body
asyncCheck(asyncproc())
# The 'do' notation allows passing in a block of code to the last parameter in a
# template or macro.
doAsync do:
echo "hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment