This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-11
Channels
- # announcements (38)
- # babashka (5)
- # beginners (26)
- # calva (26)
- # cider (1)
- # clj-kondo (36)
- # cljdoc (17)
- # cljs-dev (31)
- # clojure (39)
- # clojure-australia (9)
- # clojure-berlin (2)
- # clojure-dev (31)
- # clojure-europe (22)
- # clojure-france (3)
- # clojure-italy (7)
- # clojure-nl (5)
- # clojure-norway (5)
- # clojure-spec (28)
- # clojure-uk (9)
- # clojured (20)
- # clojurescript (24)
- # community-development (2)
- # conjure (32)
- # core-async (7)
- # cryogen (6)
- # datomic (2)
- # duct (6)
- # fulcro (6)
- # graalvm (53)
- # introduce-yourself (2)
- # jobs (2)
- # luminus (2)
- # nrepl (2)
- # off-topic (35)
- # re-frame (17)
- # reveal (8)
- # shadow-cljs (27)
- # testing (2)
- # xtdb (8)
Hi, this may be related to the above discussion, but is there an idiomatic way of taking from a channel in batches with a timeout?
Ok great that’s just what I needed
Ok, pardon the question, but when I try that buffer function in my REPL I get ‘Can only recur from tail position’. What am I overlooking?
I think you should be able to just remove that last recur statement, and put those values in the loop bindings instead
ie
(defn buffer
[in ms N]
(let [out (chan)]
(go
(loop [b [(<! in)] timer (timeout ms)]
(if timer
(alt!
timer (do (>! out b)
(recur [] nil))
in ([v]
(let [new-buffer (conj b v)]
(if (= N (count new-buffer))
(do
(>! out new-buffer)
(recur [] nil))
(recur new-buffer timer))))))))
out))
(can't test it out at the moment)