weavejester / integrant

Micro-framework for data-driven architecture

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lazy seqs in opts cause `integrant.core/init` to never return

martinklepsch opened this issue · comments

;; test case

(defmethod ig/init-key :test [_ {:keys [seq]}]
  seq)

(def system
  (ig/init {:test {:seq (range)}}))

I'm not sure if this is to be expected or not but even if it is intended there should be some sort of guard IMHO.

I think if you pass an infinite lazy seq to something that is designed to consume the seq, there's not much we can do except to hang. There's plenty of other functions in Clojure that will also hang, such as (vec (range)).

@weavejester this also breaks:

  (defmethod ig/init-key :test [_ {:keys [seq]}]
    (take 2 seq))

  (def system
    (ig/init {:test {:seq (range)}}))

I understand that it will hang if the seq is being fully realized but something else outside my init function is causing the seq to be realized. Hope that makes sense :)

Ah, I see. Unfortunately that's unavoidable, since Integrant needs to walk the configuration for refs. If the configuration returns infinite seqs, the walk will never finish.

Right, now that you say it, that makes sense 😄 Is there any way users could be protected from running into this issue?

I can't think of anything except to ensure that your configurations are of a finite length.