Created
February 13, 2018 12:32
-
-
Save frankiesardo/feff98075dc3795bba07af3cbb528391 to your computer and use it in GitHub Desktop.
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 batch [in out max-time max-count] | |
(let [lim-1 (dec max-count)] | |
(async/go-loop [buf [] t (async/timeout max-time)] | |
(let [[v p] (async/alts! [in t])] | |
(cond | |
(= p t) | |
(do | |
(async/>! out buf) | |
(recur [] (async/timeout max-time))) | |
(nil? v) | |
(if (seq buf) | |
(async/>! out buf)) | |
(== (count buf) lim-1) | |
(do | |
(async/>! out (conj buf v)) | |
(recur [] (async/timeout max-time))) | |
:else | |
(recur (conj buf v) t)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment