This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-29
Channels
- # babashka (64)
- # beginners (60)
- # calva (10)
- # circleci (3)
- # clj-kondo (62)
- # cljdoc (6)
- # clojars (2)
- # clojure (152)
- # clojure-europe (19)
- # clojure-nl (3)
- # clojure-uk (18)
- # clojurescript (50)
- # clojureverse-ops (12)
- # core-async (21)
- # cursive (6)
- # data-science (1)
- # datomic (17)
- # events (14)
- # fulcro (64)
- # graalvm (20)
- # graphql (5)
- # honeysql (14)
- # jackdaw (3)
- # jobs (1)
- # jobs-discuss (22)
- # kaocha (2)
- # lsp (9)
- # luminus (8)
- # malli (30)
- # meander (31)
- # other-languages (1)
- # polylith (8)
- # re-frame (15)
- # shadow-cljs (85)
- # specter (2)
- # sql (11)
- # tools-deps (56)
- # vim (39)
- # vscode (7)
- # xtdb (16)
Hello, anyone knows why this returns nil?
(let [c (a/chan)]
(a/>!! c "Blocking - not in go-block")
(a/<!! c))
c
is an unbuffered channel and it will forever block at (a/>!! c "Blocking - not in go-block")
since it's impossible for anyone else to read from the channel
I'm not sure what makes it look like it's returning nil. Maybe your repl is timing out and just returning nil?
changing the buffer size to 1 will return "Blocking - not in go-block"
(let [c (a/chan 1)]
(a/>!! c "Blocking - not in go-block")
(a/<!! c))
;; "Blocking - not in go-block"
It actually seems like it's not the issue. Your snippet also returns nil.
not in my repl
I'm on clojurescript though, and I've got an error in the repl which says that >!! is undeclared
That makes sense
I'm not entirely sure how I'm supposed to take the value out of a go block then?
I'm less familiar with cljs core.async at this point, but there at least 3 options:
• take!
• poll!
• wrap your <!
in another go block
You don't really. One way to communicate some value out of a go block would be to modify an atom, but because of how JS works once you're in async code (like a go block) there isn't really a good way out of it.
I think I remember seeing some integration with promises/await, but I don't have link handy at the moment
Yeah I see
right, but await et al are still just right back in async code since you can only await in an async function.
unless I'm remembering my js wrong.
I can only pass values around, but not evaluate some async code in the repl and get a result
> right, but await et al are still just right back in async code It is core.async after all
even on the jvm
, <!!
is blocking, but it's still asynchronous. It's just a matter of whether you want to use the OS scheduler or the scheduler that core.async's go
macro uses (there are some other resource differences too).