This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-25
Channels
- # aleph (2)
- # aws (2)
- # beginners (37)
- # boot (23)
- # cider (29)
- # clara (34)
- # cljs-dev (2)
- # cljsrn (17)
- # clojure (230)
- # clojure-dev (47)
- # clojure-italy (11)
- # clojure-nl (2)
- # clojure-poland (5)
- # clojure-russia (52)
- # clojure-sg (1)
- # clojure-spec (70)
- # clojure-uk (73)
- # clojurescript (31)
- # core-async (9)
- # cursive (15)
- # datomic (39)
- # events (1)
- # graphql (1)
- # lein-figwheel (2)
- # luminus (13)
- # off-topic (2)
- # onyx (29)
- # other-lisps (1)
- # parinfer (15)
- # pedestal (14)
- # re-frame (41)
- # reagent (24)
- # ring (4)
- # ring-swagger (12)
- # rum (1)
- # spacemacs (3)
- # specter (1)
- # test-check (13)
- # timbre (9)
- # unrepl (29)
- # vim (5)
I’m just missing something simple here. Do we know why this code only works when the timeout channel wins?
(def c (chan))
(let [begin (System/currentTimeMillis)
[v ch] (async/alts!! [c (async/timeout 5000)])]
(println "Message: " v)
(println "Timer: " (- (System/currentTimeMillis) begin)))
;; Should call if we want the non-timeout channel to win... But the call from async/alts!! just hangs
(>!! c "Hello World")
Yes, it will just block because nothing has been put into the channel yet.
And your let block is running on the repl thread
You need to wrap the let block in something like async/thread
@tbaldridge Thanks, yeah just figured it out. I put the production in a go block.
(defn foo
[value c]
(go (>! c value)))
(let [c1 (chan)]
(foo "Hello" c1)
(let [[v channel] (alts!! [c1 (timeout 1000)])]
(if v
(println "Value: " v)
(println "Timed out!"))))
@twashing sure, but dont use alts!! in that case, use alts!. If you use the !! you can quite easily starve the go thread pool.