Created
March 9, 2021 08:00
-
-
Save Araq/1de715551a8ae38d1aa3328e8a5a6945 to your computer and use it in GitHub Desktop.
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
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