<< Back to previous view

[ASYNC-183] Completion arity of transducer is called twice Created: 20/Jan/17  Updated: 23/Feb/19

Status: Open
Project: core.async
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Jozef Wagner Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: chan, transducers


 Description   

completion arity (1) of a transducer function is called twice in a channel

(let [xf (fn [rf]
           (fn
             ([] (println "INIT") (rf))
             ([result] (println "COMPLETING") (rf result))
             ([result input] (println "STEP") (rf result input))))
      c (chan 10 xf)]
  (close! c)
  (println "RESULT" (<!! c)))

will print

COMPLETING
COMPLETING
RESULT nil

According to https://clojure.org/reference/transducers, it is probably a bug:

> A completing process must call the completion operation on the final accumulated value exactly once

Looks like completing fn is called at there places in core.async: https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/impl/channels.cljs#L122 https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/impl/channels.cljs#L146



 Comments   
Comment by Jan Rychter [ 23/Feb/19 11:29 AM ]

I can confirm that I also encountered this and was surprised by the behavior.

Generated at Thu Apr 18 21:28:35 CDT 2019 using JIRA 4.4#649-r158309.