Skip to content

Instantly share code, notes, and snippets.

@cgrand
Created March 31, 2010 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrand/350146 to your computer and use it in GitHub Desktop.
Save cgrand/350146 to your computer and use it in GitHub Desktop.
;; similar to http://clj-me.cgrand.net/2009/11/18/are-pipe-dreams-made-of-promises/ but without the spinning atom
(defn pipe []
(let [q (java.util.concurrent.LinkedBlockingQueue.)
EOQ (Object.)
NIL (Object.)
s (fn s [] (lazy-seq (let [x (.take q)] (when-not (= EOQ x) (cons (when-not (= NIL x) x) (s))))))]
[(s) (fn ([] (.put q EOQ)) ([x] (.put q (or x NIL))))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment