Skip to content

Instantly share code, notes, and snippets.

@Araq
Created March 9, 2021 08:00
Show Gist options
  • Save Araq/1de715551a8ae38d1aa3328e8a5a6945 to your computer and use it in GitHub Desktop.
Save Araq/1de715551a8ae38d1aa3328e8a5a6945 to your computer and use it in GitHub Desktop.
discard """
cmd: "nim c --gc:orc $file"
output: '''
{"age": 12, "bio": "Я Cletus", "blob": [65, 66, 67, 128], "name": "Cletus"}
true
true
alpha 100
omega 200
0'''
"""
echo 133'foo
echo "ho"
when false:
type
Foo = object
FooRef = ref Foo
Bar = ref object
f: FooRef
proc `=destroy`(o: var Foo) =
echo "destroy Foo"
proc testMe(x: Bar) =
var c = (if x != nil: x.f else: nil)
if cond:
assert c != nil
proc main =
var b = Bar(f: FooRef())
testMe(b)
main()
when false:
import asyncdispatch
type
Flags = ref object
returnedEof, reading: bool
proc dummy(): Future[Flags] {.async.} =
result = Flags(reading: false)
#raise newException(ValueError, "meh")
proc hello(s: Flags) {.async.} =
let buf =
try:
await dummy()
except CatchableError as exc:
# When an exception happens here, the Bufferstream is effectively
# broken and no more reads will be valid - for now, return EOF if it's
# called again, though this is not completely true - EOF represents an
# "orderly" shutdown and that's not what happened here..
s.returnedEof = true
raise exc
finally:
s.reading = false
doAssert not isNil(buf), "connection died after upgradeOutgoing"
waitFor hello(Flags())
when false:
var ch = initChan[int]()
for i in 0 ..< 100:
echo i, " ", ch.trySend i
var v = 0
echo ch.tryRecv(v)
echo v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment