Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 584
Arthur Ulfeldt Avatar asked Feb 13 '14 02:02

Arthur Ulfeldt


1 Answers

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.

like image 193
Alex Miller Avatar answered Oct 31 '22 12:10

Alex Miller