This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-07
Channels
- # announcements (1)
- # architecture (9)
- # babashka (3)
- # calva (10)
- # clj-http (13)
- # clj-kondo (11)
- # clojure (23)
- # clojure-europe (11)
- # clojure-nl (1)
- # clojure-norway (112)
- # clojure-uk (4)
- # clojuredesign-podcast (8)
- # clojurescript (10)
- # core-async (5)
- # cursive (7)
- # data-science (15)
- # datascript (2)
- # datomic (29)
- # emacs (5)
- # events (1)
- # hugsql (1)
- # hyperfiddle (9)
- # midje (1)
- # missionary (3)
- # music (1)
- # off-topic (34)
- # polylith (1)
- # re-frame (16)
- # shadow-cljs (117)
- # squint (19)
- # yamlscript (1)
Could I get help understanding some behavior of core.async?
I may be introducing a race condition.
I'm using the latest version: 1.6.681
Here is my code testing a/mult
and a/tap
(defn mult-test
[input]
(let [buffer-size (count input)
source-items (doto (a/chan buffer-size)
(a/onto-chan! input))
mult-source (a/mult source-items)
a-items (a/chan buffer-size (map (fn [i]
(println "a ITEM" i)
{:a i})))
b-items (a/chan buffer-size (map (fn [i]
(println "b ITEM" i)
{:b i})))]
(a/tap mult-source a-items)
(a/tap mult-source b-items)
(println "=======================")
(println "got: " (first (a/alts!! [a-items b-items])))))
(mult-test (range 5))
Calling (mult-test (range 5))
from my REPL usually prints what I would expect
=======================
a ITEM 0
got: b ITEM 0
{:a 0}
a ITEM 1
b ITEM 1
...
but sometimes it prints only the following and hangs indefinitely.
=======================
I know that the a/alts!!
call is blocking, but I thought that by calling the a/tap
calls immediately prior, the a-items
and b-items
channels should start filling up in the background even if my main thread is blockingMult runs a go loop that copies the input to the output, and you are racing that go loop