This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-16
Channels
- # aws (6)
- # beginners (129)
- # calva (9)
- # cider (4)
- # cljs-dev (2)
- # clojure (41)
- # clojure-beijing (2)
- # clojure-dev (3)
- # clojure-spec (23)
- # clojure-uk (46)
- # clojurescript (38)
- # community-development (20)
- # core-async (4)
- # cursive (12)
- # data-science (7)
- # datascript (13)
- # datomic (15)
- # duct (11)
- # emacs (18)
- # figwheel-main (5)
- # fulcro (26)
- # off-topic (4)
- # pathom (28)
- # pedestal (3)
- # reagent (8)
- # reitit (6)
- # shadow-cljs (32)
- # specter (3)
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!