Skip to content

Commit

Permalink
Fix delayed middleware loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Cartmanishere committed Nov 22, 2020
1 parent 22c3356 commit c63701c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/cider/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,26 @@
(or (resolve sym)
(throw (IllegalArgumentException. (format "Cannot resolve %s" sym)))))

(defn- handler-future
[sym ns fn-name]
(or (get @delayed-handlers sym)
(get (swap! delayed-handlers assoc sym
(delay
(locking require-lock
(require ns)
(resolve-or-fail fn-name))))
sym)))

(defmacro run-deferred-handler
"Make a delay out of `fn-name` and place it in `delayed-handlers` atom at compile time.
Require and invoke the delay at run-time with arguments `handler` and
`msg`. `fn-name` must be a namespaced symbol (unquoted)."
[fn-name handler msg]
(let [ns (symbol (namespace `~fn-name))
sym (symbol (name `~fn-name))]
(swap! delayed-handlers assoc sym
(delay
(locking require-lock
(require `~ns)
(resolve-or-fail `~fn-name))))
`(@(get @delayed-handlers '~sym) ~handler ~msg)))
`(@(handler-future '~sym '~ns '~fn-name)
~handler ~msg)))


(defmacro ^{:arglists '([name handler-fn descriptor]
[name handler-fn trigger-it descriptor])}
Expand Down

0 comments on commit c63701c

Please sign in to comment.