Skip to content
Browse files

add yield-close

  • Loading branch information...
1 parent f55ad33 commit d0210d55bd07fe0f4489537da9d872646508a726 @jpalmucci committed
Showing with 8 additions and 11 deletions.
  1. +0 −3 README
  2. +8 −8 src/yield.clj
@@ -35,6 +35,3 @@ inside the body of a with-yielding.)
thread. Lazy sequences acting as buffered queues are great at
sychronizing producer and consumer threads.
-TODO: document record-blockage
16 src/yield.clj
@@ -43,7 +43,12 @@ with-yielding should return."
[yseq exception]
(offer yseq (ExceptionContainer. exception)))
-(defmacro with-yielding [[name n & {position :position}] & body]
+(defn yield-close
+ "Close the yield stream. Any future yields to the stream result in an exception."
+ [yseq]
+ (reset! yseq nil))
+(defmacro with-yielding [[name n] & body]
"Construct and return a sequence that is filled using 'yield' from
within the body. The body can get up to 'n' elements ahead of the
sequence consumer before blocking on 'yield'. For example:
@@ -66,20 +71,15 @@ user> (first *test-sequence*)
Yielding 4
-If 'position' is given, use that value to identify this sequence
-for 'record-blockage'.
`(with-yielding* ~n
(^{:once true} fn* [~name]
- ~@body))
- ~(if (nil? position)
- `(file-position 1)
- position)))
+ ~@body))))
-(defn with-yielding* [n f pos]
+(defn with-yielding* [n f]
(let [queue (java.util.concurrent.ArrayBlockingQueue. (int n) false)
queue-atom (atom queue)
out *out*

0 comments on commit d0210d5

Please sign in to comment.
Something went wrong with that request. Please try again.