Skip to content

Instantly share code, notes, and snippets.

@philip-wernersbach
Created January 25, 2016 20:50
Show Gist options
  • Save philip-wernersbach/6b79493b39da03b3b71e to your computer and use it in GitHub Desktop.
Save philip-wernersbach/6b79493b39da03b3b71e to your computer and use it in GitHub Desktop.
# Run with "nim cpp -r"
import asyncdispatch
# This doesn't work because the Nim compiler generates a goto that
# jumps into a try block.
#
# In C++ you can jump out of a try block, but not into it. In addition,
# jumping out of the try block here isn't valid behavior, because C++
# will execute applicable destructors.
proc test() {.async.} =
var foo: pointer = nil
defer:
# In my real code, foo is a pointer to a non-GC variable that
# I have to ensure is freed
foo = nil
await sleepAsync(100)
asyncCheck test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment