This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-14
Channels
- # aleph (2)
- # atlanta-clojurians (5)
- # beginners (38)
- # boot (2)
- # bristol-clojurians (1)
- # cider (31)
- # clara (8)
- # cljs-dev (136)
- # cljsrn (4)
- # clojure (86)
- # clojure-china (1)
- # clojure-greece (1)
- # clojure-italy (24)
- # clojure-nl (1)
- # clojure-spec (21)
- # clojure-uk (19)
- # clojurescript (68)
- # community-development (28)
- # core-async (35)
- # core-logic (4)
- # cursive (1)
- # data-science (1)
- # datascript (1)
- # datomic (46)
- # events (1)
- # figwheel (6)
- # fulcro (11)
- # graphql (3)
- # hoplon (1)
- # jobs (6)
- # jobs-discuss (94)
- # keechma (3)
- # luminus (4)
- # lumo (7)
- # mount (6)
- # off-topic (24)
- # onyx (6)
- # parinfer (31)
- # portkey (3)
- # programming-beginners (16)
- # re-frame (20)
- # reagent (69)
- # remote-jobs (4)
- # ring-swagger (25)
- # schema (1)
- # shadow-cljs (151)
- # spacemacs (2)
- # sql (14)
- # tools-deps (16)
- # uncomplicate (5)
- # unrepl (35)
- # vim (1)
- # yada (72)
Hey I’ve got a small question concerning threads. I have a producer and consumer. Unfortunatelly I can’t find anything like Thread.join
from java to wait until all threads quit. Probably I just misunderstood the concept of core/async
apparently it help to create a dummy thread looping infinitely to keep channels running. Doesn’t feel right, though
You can block on all the channels in the primary thread. (run! async/<!! <coll-of-core.async-threads>)
Not sure I understood. Why is the application blocking at this point? eventhough there might be a message comming to the channel?
I’m not sure what you’re trying to do. <!!
is a blocking take from a channel. That’ll block until either a message is put on the channel or the channel is closed.
For the testing scenario I created a go-loop that listens to the same channel; last command in the app is <!! channel
and before that I send a message in a separate thread. The go loop prints out the message but the program does not quit. Why doesn’t it quit although there was a message and the blocking read should have passed? Because the go-loop picked the message before the last (<!! channel) ?
I have a $something-preprocessing loop, that processes data and sends a message on a channel. this message shall be processed in another thread. The pre-processing runs much faster than the actual processing
I thought core.async might be the right tool for that. Otherwise I would have realized this with ordinary java threads…
(def inbound (chan 10))
(go-loop []
(let [msg (<! inbound)]
(when msg
(println "Channel:" msg)))
(recur))
(future (Thread/sleep 1000) (>!! inbound "Some message"))
(<!! inbound)
(println "I am never called…")
; Channel: Some message
Like i said it’s being printed. Just as expected. I just don’t undestand, why the application blocks at (<!! inbound)
So for my understanding the go-loop gets the message first, so that the “message queue” is emptied before (<!! inbound)
can pick it up?
is there a chance that the go-loop misses the message? Or is the order of consumption already defined the order of consumers in the code?