Thank you, dom96. This is my simple code:
import asyncdispatch, threadpool
var started = false
proc process() {.async.} =
if started: return
started = true
echo "start process"
while started:
echo "..."
await sleepAsync(5000)
echo "stop process"
proc main() {.async.} =
var msg = spawn stdin.readLine()
while true:
if msg.isReady():
case ^msg:
of "stop": started = false
of "start": asyncCheck process()
of "bye":
if started: echo"enter stop before" else: return
else: echo"invalid command"
msg = spawn stdin.readLine()
await sleepAsync(500)
waitFor main()
After a few seconds cpu load ~50%. What am I doing wrong?