Created
February 25, 2021 21:17
-
-
Save michaelsbradleyjr/d4aed98d91a6a4a132274bd66e5af826 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
import os, stew/faux_closures, threadpool | |
type | |
MyString* = distinct cstring | |
proc mine*(input: string): MyString = | |
input.cstring.MyString | |
proc `$`*(input: MyString): string = | |
$(input.cstring) | |
proc sendSignal(data: string, name: string) = | |
echo name & ": " & data | |
template spawnAndSend(name: string, exprToSend: untyped) = | |
let nameCstr = name.mine | |
proc payload {.fauxClosure.} = | |
let data: string = exprToSend | |
sendSignal(data, $nameCstr) | |
spawn payload() | |
# L20 triggers a compiler error: | |
# bar.nim(20, 16) Error: type mismatch: got <MyString> | |
# but expected one of: | |
# proc payload_16600094(nameCstr`gensym16591097_16600096: distinct[cstring]) | |
# first type mismatch at position: 1 | |
# required type for nameCstr`gensym16591097: distinct cstring | |
# but expression 'nameCstr`gensym16591097' is of type: MyString | |
# | |
# expression: payload_16600094(nameCstr`gensym16591097) | |
proc foo(bar: string) = | |
spawnAndSend(bar) do: | |
"foo" | |
foo("bar") | |
sleep(2) | |
# Run with `./env.sh nim c -r --threads:on --tlsEmulation:off bar.nim` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment