Skip to content

Commit 978348b

Browse files
committed
Only require the given ns sym if it wasn't previously loaded. Also, use the threads for :io workloads to run the require.
1 parent babf4ed commit 978348b

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/main/clojure/clojure/core/async.clj

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -516,24 +516,25 @@ IOC and vthread code.
516516
(let [ret (impl/take! port (fn-handler nop false))]
517517
(when ret @ret)))
518518

519-
(defn- dynamic-require [& args]
520-
(let [p (promise)
521-
n *ns*
522-
ll @#'clojure.core/*loaded-libs*]
523-
(.start
524-
(Thread.
525-
(fn []
526-
(try
527-
(let [result (binding [*ns* n
528-
clojure.core/*loaded-libs* ll]
529-
(apply require args))]
530-
(deliver p result))
531-
(catch Throwable t
532-
(deliver p t))))))
533-
(let [res @p]
534-
(if res
535-
(throw res)
536-
res))))
519+
(defn- dynamic-require [nsym]
520+
(when (not (contains? @@#'clojure.core/*loaded-libs* nsym))
521+
(let [p (promise)
522+
n *ns*
523+
ll @#'clojure.core/*loaded-libs*]
524+
(dispatch/exec
525+
(^:once fn* []
526+
(try
527+
(let [result (binding [*ns* n
528+
clojure.core/*loaded-libs* ll]
529+
(require nsym))]
530+
(deliver p result))
531+
(catch Throwable t
532+
(deliver p t))))
533+
:io)
534+
(let [res @p]
535+
(if res
536+
(throw res)
537+
res)))))
537538

538539
(defmacro go
539540
"Asynchronously executes the body, returning immediately to the
@@ -554,10 +555,9 @@ IOC and vthread code.
554555
(if go-becomes-ioc?
555556
(do (dynamic-require 'clojure.core.async.impl.go)
556557
((find-var 'clojure.core.async.impl.go/go-impl) &env body))
557-
(let [rt-check-step (when clojure.core/*compile-files*
558-
`(dispatch/ensure-runtime-vthreads!))]
559-
`(do ~rt-check-step
560-
(thread-call (^:once fn* [] ~@body) :io)))))
558+
`(do ~(when clojure.core/*compile-files*
559+
`(dispatch/ensure-runtime-vthreads!))
560+
(thread-call (^:once fn* [] ~@body) :io))))
561561

562562
(defonce ^:private thread-macro-executor nil)
563563

0 commit comments

Comments
 (0)