Transducers on channels lock the channel while they are running. This is by design. So yes, the side-effect of this means that no other operation (puts, takes or closes) can succeed while the transducer is running.
So the short answer is: If you have code that can take awhile to run, don't put it in a channel transducer, put it in `async/pipeline(-blocking)` instead. On Mon, Jul 3, 2017 at 12:03 PM, Vitalie Spinu <spinu...@gmail.com> wrote: > > Hi, > > Async/close! causes deadlocks if its reducer is stalled (e.g. waits for an > event from > another chan). > > Consider: > > (let [d (chan) > s (chan 1 (map (fn [v] > (println "this:" v) > (println "from d:" (<!! d)) > v)))] > (go (>! s 1)) > (Thread/sleep 100) > (println "closing s") > (async/close! s)) > > ;; => > ;; this: 1 > ;; closing s > ;; .. [lock] > > This is caused by (.lock mutex) in close! method here: > > https://github.com/clojure/core.async/blob/master/src/ > main/clojure/clojure/core/async/impl/channels.clj#L247 > > I wonder if it is there "by design" or a bug. IMO it makes little sense to > lock > external code simply because chan's reducer function is stalled. Just as > close! > doesn't lock on pending puts it shouldn't stall on pending "half-puts". > > I need this for systems with inter-dependent chans. In the above example > component 'd' is a dependency of 's', then system will halt in reverse > order of > dependencies closing `s` first. > > Thank you, > > Vitalie > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.