core-async

2020-03-02T18:34:28.195300Z

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

ghadi 2020-03-02T18:39:50.195600Z

@thegeez is that async/transduce?

ghadi 2020-03-02T18:39:57.195800Z

no I guess not

2020-03-02T18:46:27.196700Z

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

ghadi 2020-03-02T18:51:28.197200Z

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

ghadi 2020-03-02T18:51:34.197400Z

@thegeez

ghadi 2020-03-02T18:51:53.197900Z

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

2020-03-02T18:53:46.198700Z

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

2020-03-02T18:54:38.199900Z

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

ghadi 2020-03-02T18:54:43.200100Z

halt-when ends transduction

ghadi 2020-03-02T18:54:51.200400Z

cool! thanks @thegeez

ghadi 2020-03-02T18:55:24.200900Z

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

ghadi 2020-03-02T18:58:52.201400Z

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

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

2020-03-02T19:04:18.202500Z

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