Uploaded image for project: 'core.async'
  1. ASYNC-183

Completion arity of transducer is called twice

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Labels:

      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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              wagjo Jozef Wagner
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: