I have a question about interacting with core.async
from the repl. My goal is to essentially create an async while loop that executes continuously (and prints out a "running..." message every 5 seconds or so) until I either send a message to a channel that tells it to stop or update the state of an atom that invalidates the condition of the wile loop. What's the best way to do this?
I thinking it’ll look like this
(def stop-chan (async/chan))
(async/go-loop []
(let [[v c] (async/alts! [stop-chan (async/timeout 5000)])]
(if (or (= c stop-chan) (pos? @atom))
(do
(prn "END")
(async/close! stop-chan))
(do
(prn "WORK")
(recur)))))
=> "WORK"
=> "WORK"
...
(async/close stop-chan)
This was helpful, thanks!
And for an atom you just need to add another condition and also close stop-chan