# Well, Claude's down, so this is going to take a bit longer... here's a minimal # reproducer though, maybe I'm doing something wrong, but I'd expect this to work: # ```import std/[asyncdispatch, times, exitprocs] # type # MessageKind = enum # write, stop # Message = object # case kind: MessageKind # of write: # text: string # of stop: # discard # var channel: Channel[Message] # var logThread: Thread[void] # proc logThreadProc() {.thread.} = # stderr.writeLine "[THREAD] Logger thread started" # var msgCount = 0 # while true: # let msg = recv channel # inc msgCount # stderr.writeLine "[THREAD] Received message #" & $msgCount # case msg.kind # of write: # echo msg.text # flushFile(stdout) # of stop: # break # proc initLogger() = # open channel # createThread(logThread, logThreadProc) # proc stopLogger() {.noconv.} = # channel.send Message(kind: stop) # joinThread logThread # close channel # # threadedlogger.nim # proc log(text: string) = # channel.send Message(kind: write, text: text) # proc periodicLogger() {.async.} = # var count = 0 # while true: # inc count # stderr.writeLine "[STDERR] Before channel.send #" & $count # log "[CHANNEL] Async log #" & $count & " at " & $now() # stderr.writeLine "[STDERR] After channel.send #" & $count # await sleepAsync(1000) # when isMainModule: # initLogger() # addExitProc stopLogger # log "[CHANNEL] Starting test..." # log "[CHANNEL] Logger thread initialized" # stderr.writeLine "[STDERR] Starting test..." # asyncCheck periodicLogger() # log "[CHANNEL] About to call runForever()..." # stderr.writeLine "[STDERR] About to call runForever()..." # # BUG: After this call, the logger thread's recv() never wakes up again # runForever()