Guest User

Untitled

a guest
Feb 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. (defn batch [in out max-time max-count]
  2. (let [lim-1 (dec max-count)]
  3. (async/go-loop [buf [] t (async/timeout max-time)]
  4. (let [[v p] (async/alts! [in t])]
  5. (cond
  6. (= p t)
  7. (do
  8. (async/>! out buf)
  9. (recur [] (async/timeout max-time)))
  10.  
  11. (nil? v)
  12. (if (seq buf)
  13. (async/>! out buf))
  14.  
  15. (== (count buf) lim-1)
  16. (do
  17. (async/>! out (conj buf v))
  18. (recur [] (async/timeout max-time)))
  19.  
  20. :else
  21. (recur (conj buf v) t))))))
Add Comment
Please, Sign In to add comment