This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-04
Channels
- # architecture (20)
- # aws (8)
- # beginners (13)
- # boot (9)
- # cider (80)
- # cljs-dev (69)
- # cljsrn (7)
- # clojure (243)
- # clojure-dusseldorf (8)
- # clojure-italy (5)
- # clojure-norway (3)
- # clojure-poland (57)
- # clojure-russia (10)
- # clojure-shanghai (2)
- # clojure-spec (11)
- # clojure-uk (50)
- # clojurescript (198)
- # core-async (11)
- # crypto (2)
- # cursive (14)
- # datomic (17)
- # figwheel (8)
- # garden (7)
- # hoplon (8)
- # incanter (4)
- # jobs (1)
- # leiningen (1)
- # liberator (38)
- # lumo (28)
- # om (55)
- # onyx (10)
- # pedestal (13)
- # perun (20)
- # re-frame (1)
- # reagent (16)
- # ring-swagger (9)
- # spacemacs (11)
- # test-check (9)
- # unrepl (43)
- # untangled (163)
- # yada (8)
When I run (go (while true (prn (<! channel)))
shouldn't it stop, when the channel is empty? In my case its repeats printing nil
until i kill the process. I use core.async under cljs.
@danielgrosse You need to make the loop condition depend on whether the channel is closed (i.e. whether a take returned nil
)
Like (go (while (not (nil?)) (foo)))
?
Yeah but while
is not a good fit here, better go with loop
/`recur`
Like (go (loop [] (when-some [x (<! channel)] (prn x) (recur))))
, for example
Or use the go-loop
shorthand if you like
With while
you couldn't use the value read from the channel in case it isn't yet closed and exhausted
Thank you, when-some was the clue.
@danielgrosse I use this
(defmacro while-let
[test-binding & body]
`(loop []
(when-let ~test-binding
~@body
(recur))))
for exactly that sort of scenario