Skip to content

Instantly share code, notes, and snippets.

@ray1729
Last active August 29, 2015 13:57
Show Gist options
  • Save ray1729/9812546 to your computer and use it in GitHub Desktop.
Save ray1729/9812546 to your computer and use it in GitHub Desktop.
(ns rollup.core
(:require [clojure.core.async :refer [go chan <! put! timeout alt! alts!]]))
(def ch (chan))
(go
(loop [stash []]
(let [[v c] (alts! [ch (timeout 3000)])]
(if (= c ch)
(when v
(when (< (count stash) 5)
(println "A" v))
(recur (conj stash v)))
(do
(when (not-empty stash)
(println "B" stash))
(recur []))))))
(dotimes [n 20] (put! ch n))
(clojure.core.async/close! ch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment