juxt / clip

Light structure and support for dependency injection
MIT License
228 stars 15 forks source link

`clip/stop` runs stop functions twice #11

Closed onetom closed 4 years ago

onetom commented 4 years ago
  (def cfg {:components
            {:wheel {:start {:part "wheel"}
                     :stop  prn}}})
  (def sys (clip/start cfg))
  (clip/stop cfg sys)
=> #'repl/cfg
=> #'repl/sys
{:part "wheel"}
{:part "wheel"}
=> {:wheel nil}

and the implementation indeed seems to simply repeat the stop operation:

(defn stopping-f
  [[k {:keys [stop]}]]
  (fn [rf acc]
    (stop! (get acc k) stop)
    (-> acc
        (rf k (stop! (get acc k) stop)))))

https://github.com/juxt/clip/blob/26cb6c926b42c8b8886149d5c65c6d6568ad1cc8/src/juxt/clip/impl/core.cljc#L337-L342

onetom commented 4 years ago

Here is a temporarily workaround for the issue. Put this into your user.clj:

(intern
  'juxt.clip.impl.core 'stopping-f
  (fn
    [[k {:keys [stop]}]]
    (fn [rf acc]
      ;(juxt.clip.impl.core/stop! (get acc k) stop)
      (-> acc
          (rf k (juxt.clip.impl.core/stop! (get acc k) stop))))))
SevereOverfl0w commented 4 years ago

You're right to post this here, I did forget :)