clj-commons / manifold

A compatibility layer for event-driven abstractions
1.02k stars 108 forks source link

Construction of chain with clojure.core/apply causes hang in some circumstances #50

Closed malcolmsparks closed 9 years ago

malcolmsparks commented 9 years ago

Probably related to #48

Here are some examples. The second one hangs on the deref.

Possibly a bug.?

(require '[manifold.deferred :as d])

;; an example with applying d/chain to a vector of functions.

;; ok
(deref (d/chain
        nil
        identity
        (fn [_]
          (d/chain 100
                   (fn [v]
                     (d/future (str v)))))
        identity))

))

;; hangs!
(deref (apply d/chain
              nil
              [identity
               (fn [_]
                 (d/chain 100
                          (fn [v]
                            (d/future (str v)))))
               identity]))

;; is ok if one of other of the identity functions is omitted
(deref (apply d/chain
              nil
              [#_identity
               (fn [_]
                 (d/chain 100
                          (fn [v]
                            (d/future (str v)))))
               identity]))

;; but reduce is ok
(deref (reduce (fn [c n] (d/chain c n)) {}
               [identity
                (fn [_]
                  (d/chain 100
                           (fn [v]
                             (d/future (str v)))))
                identity]))