Permalink
Browse files

Fixing bug on produce-seq, was not yielding value when consumer was done

  • Loading branch information...
1 parent 1574e65 commit cac765718517b49f01a44744db7609525edf880c @roman committed Mar 6, 2012
Showing with 14 additions and 4 deletions.
  1. +4 −4 src/river/seq.clj
  2. +10 −0 test/river/test/seq.clj
View
@@ -189,11 +189,11 @@
(fn producer [consumer0]
(loop [consumer consumer0
a-seq a-seq0]
- (let [[input remainder] (core/split-at chunk-size a-seq)
- next-consumer (consumer input)]
(cond
- (yield? next-consumer) next-consumer
- (continue? next-consumer)
+ (yield? consumer) consumer
+ (continue? consumer)
+ (let [[input remainder] (core/split-at chunk-size a-seq)
+ next-consumer (consumer input)]
(if (empty? remainder)
(continue next-consumer)
(recur next-consumer remainder))))))))
View
@@ -45,6 +45,16 @@
(is (= [0 0 0 1] (:result result)))
(is (= eof (:remainder result)))))
+(deftest producers-with-yield-consumer-test
+ (let [producers [(rs/produce-seq (range 1 10))
+ (rs/produce-unfold binary-unfold 8)
+ (rs/produce-repeat "hello")
+ (rs/produce-replicate 10 "hello")
+ (rs/produce-iterate inc 1)]]
+ (doseq [p producers]
+ (is (= 5 (:result (run p (yield 5 []))))
+ (str "producer " p " doesn't work when consumer is yield.")))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Consumers

0 comments on commit cac7657

Please sign in to comment.