Fork me on GitHub
#core-async
<
2020-03-02
>
thegeez18:03:28

(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'?

ghadi18:03:50

@thegeez is that async/transduce?

ghadi18:03:57

no I guess not

thegeez18:03:27

No the transduce is the normal clojure transduce to check my sanity :)

ghadi18:03:28

halt-when doesn't create an additional input for the channel, IIRC

ghadi18:03:53

do the same thing with (sequence (halt-when...) ...)

thegeez18:03:46

@ghadi I see, then I had the wrong expectation for halt-when when used with a channel

thegeez18:03:38

Thanks for the help (I ran into this while listening to your latest cognicast, which I enjoyed)

ghadi18:03:43

halt-when ends transduction

ghadi18:03:24

halt-when might trigger flushing of something like partition-all

ghadi18:03:52

(sequence (comp (halt-when #{3} vector) (partition-all 2)) [1 2 4 5 :end 3 :no 5 5])

;; =>
([1 2] [4 5] [:end])

thegeez19:03:18

The lesson here for me is to use 'sequence' instead of 'tranduce conj []' to check channel stuff