core-async

respatialized 2019-02-16T17:56:31.038600Z

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?

2019-02-16T18:08:59.039700Z

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)

respatialized 2019-02-17T19:13:42.041300Z

This was helpful, thanks!

2019-02-16T18:16:17.040800Z

And for an atom you just need to add another condition and also close stop-chan