Clojure how to stop all go blocks or close all channels in core.async
Asked Answered
L

1

15

all to often when I'm using core.async from the repl a go block will get away from me because I loose the channel that is used to stop it because I reload a namespace. For instance if i run this from the repl:

(go (when (not= c (second (async/alts! [c (async/timeout 1000)]))) 
      (println "hello")))

and then I reload the namespace and c is lost. Now I have "hello" spamming my REPL until the end of time. If I could close all channels or kill all go blocks it would save me restarting my REPL.

Loveinidleness answered 13/2, 2014 at 2:33 Comment(0)
D
9

There is no way to do this globally that I know of. One technique is to use a control channel that can be used to shut down any loop. The pub/sub stuff might work well for a global control channel.

Demott answered 13/2, 2014 at 3:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.