Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (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))))))
Add Comment
Please, Sign In to add comment