mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-09 19:56:09 +00:00
32b86bfd1f
This code is extracted from the error-handling proposal where it's used to implement `Try` blocks (Faux closures are created there in order to assign raises lists to them). The desktop team faced a similar problem where the `spawn` API doesn't support closures, but the restriction can be easily worked-around with faux closures.
23 lines
340 B
Nim
23 lines
340 B
Nim
import
|
|
os, threadpool,
|
|
../stew/faux_closures
|
|
|
|
template sendSignal(data: string) =
|
|
echo data
|
|
|
|
template spawnAndSend(exprToSend: untyped) =
|
|
proc payload {.fauxClosure.} =
|
|
let data = exprToSend
|
|
sendSignal data
|
|
|
|
spawn payload()
|
|
|
|
proc main(x: string) =
|
|
spawnAndSend:
|
|
var i = 10
|
|
x & $(23 + i)
|
|
|
|
main("tests")
|
|
sleep(2)
|
|
|