(def halt-when-error-key
(halt-when :error
(fn [_result item]
(println "matching item: " item)
(assoc item :added :key))))
(transduce
halt-when-error-key
conj
[]
[{:error :foo}]) ;; => {:error :foo, :added :key}
(def pc (a/promise-chan
halt-when-error-key))
(a/take! pc (fn [res]
(println "got" res)))
(a/put! pc {:error :here})
;; output seen
;; matching item: {:error :here}
;; got nil
;; output expected
;; matching item: {:error :here}
;; got {:error :foo, :added :key}
Is there a way to get the behavior as under 'output expected'?@thegeez is that async/transduce?
no I guess not
No the transduce is the normal clojure transduce to check my sanity :)
halt-when doesn't create an additional input for the channel, IIRC
do the same thing with (sequence (halt-when...) ...)
@ghadi I see, then I had the wrong expectation for halt-when when used with a channel
Thanks for the help (I ran into this while listening to your latest cognicast, which I enjoyed)
halt-when ends transduction
cool! thanks @thegeez
halt-when might trigger flushing of something like partition-all
(sequence (comp (halt-when #{3} vector) (partition-all 2)) [1 2 4 5 :end 3 :no 5 5])
;; =>
([1 2] [4 5] [:end])
The lesson here for me is to use 'sequence' instead of 'tranduce conj []' to check channel stuff