Last active
August 29, 2015 14:14
-
-
Save gre/312a35f338438259252d to your computer and use it in GitHub Desktop.
Time Bufferizing using core.async in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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