This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-04
Channels
- # admin-announcements (6)
- # alda (1)
- # announcements (3)
- # aws (4)
- # beginners (233)
- # boot (82)
- # cider (11)
- # cljsjs (21)
- # cljsrn (7)
- # clojure (262)
- # clojure-japan (1)
- # clojure-russia (129)
- # clojure-sg (2)
- # clojure-taiwan (2)
- # clojurecup (23)
- # clojurescript (162)
- # clojurex (3)
- # core-async (18)
- # cursive (81)
- # datavis (183)
- # datomic (23)
- # emacs (2)
- # funcool (25)
- # ldnclj (82)
- # lein-figwheel (3)
- # om (196)
- # onyx (74)
- # parinfer (7)
- # portland-or (12)
- # re-frame (60)
- # reagent (48)
- # slack-help (1)
- # yada (9)
When I define a channel and use it directly, how can I close the channel later?
(let [view-chan (chan 1)]
(go-loop []
(let [response (<! view-chan)]
(println response)
)
(recur))
)
(let [view-chan (async/chan 5)]
(async/put! view-chan "a")
(async/put! view-chan "b")
(async/put! view-chan "c")
(async/go-loop []
(when-let [response (async/<! view-chan)]
(println response))
(recur))
(async/close! view-chan)
view-chan)
when reading from a channel in a loop, you should presume the channel will return nil at some point (when some other process closes it and the channel is exhausted), and loop no more.
What is the best explanation of the alts!
function you've seen?
I don’t think I’ve ever seen an explanation other than the docs, but I think of alts!
as kind of like a cond
where the clauses are the channels’ next value, and the conditions are whichever channel sends that value “first”.
(Scare quotes since the notion of order in the context of multiple threads is kind of ambiguous)
I think of it as alt! + cond
I learned alt!
much later than alts!
(and, initially, found it harder to get an intuition for)
sorry, yes
I don't love the similarity of those names
I liked your first answer too