This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-30
Channels
- # announcements (5)
- # beginners (90)
- # cider (15)
- # clara (1)
- # clj-kondo (2)
- # cljs-dev (17)
- # clojars (8)
- # clojure (132)
- # clojure-europe (14)
- # clojure-nl (5)
- # clojure-uk (57)
- # clojurescript (39)
- # code-reviews (44)
- # conjure (6)
- # core-async (6)
- # cursive (20)
- # data-science (1)
- # datomic (13)
- # fulcro (11)
- # graalvm (6)
- # graphql (6)
- # helix (10)
- # joker (2)
- # kaocha (37)
- # leiningen (24)
- # malli (15)
- # off-topic (13)
- # pathom (18)
- # pedestal (14)
- # re-frame (67)
- # reitit (5)
- # ring (13)
- # ring-swagger (4)
- # sci (41)
- # shadow-cljs (33)
- # slack-help (5)
- # spacemacs (1)
- # sql (34)
- # tools-deps (64)
- # vim (171)
- # xtdb (3)
I'm reproducing the examples of Tim Baldridge's O'Reilly course: https://resources.oreilly.com/examples/0636920041474/blob/master/Communicating%20Sequential%20Processes%20with%20core.async%20-%20Working%20Files/Chapter%205/Introduction%20to%20backpressure/Lesson_Introduction_to_Backpressure.clj
(def c (chan 24))
(go
(loop [i 0]
(println "Putting: " i)
(>! c i)
(recur (inc i))))
(<!! c)
This code demonstrates back pressure. Whenever I take a value from the channel with
(<!! c)
a new value is put onto the channel by the loop.
I closed the channel with
(close! c)
to see what happens.
Strangely, the loop no longer blocked and started printing thousands of "Putting: ..." lines. How can this be explained?
I would have expected an error.> puts a val into port. nil values are not allowed. Must be called > inside a (go ...) block. Will park if no buffer space is available. > Returns true unless port is already closed. if the put doesn't succeed, it returns false. You are attempting to put onto a closed channel which immediately returns false and then you loop again
using the >!!
version but demonstrates a similarity:
(let [closed-chan (doto (a/chan) (a/close!))]
(a/>!! closed-chan 3))
=> false
i believe your expectation was that this would block forever as it was unable to put onto the closed channel
I see. Thanks!