Skip to content

Instantly share code, notes, and snippets.

@gre
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gre/312a35f338438259252d to your computer and use it in GitHub Desktop.
Save gre/312a35f338438259252d to your computer and use it in GitHub Desktop.
Time Bufferizing using core.async in Clojure
(defn time-bufferize [in t]
(let [c (chan)]
(go
(loop
[buf []
timer (timeout t)]
(let [[value port] (alts! [in timer])
timed-out (= port timer) ]
(if (= port timer) ; timed out
(do
(>! c buf)
(recur [] (timeout t)))
(recur (conj buf value) timer)))))
c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment