@@ -85,8 +85,9 @@ IOC and vthread code.
8585
8686(alias 'core 'clojure.core)
8787
88- (def go-becomes-ioc? (not (or (dispatch/vthreads-available-and-allowed? )
89- (dispatch/target-vthreads? ))))
88+ (def ^:private go-becomes-ioc?
89+ (not (or (dispatch/vthreads-available-and-allowed? )
90+ (dispatch/target-vthreads? ))))
9091
9192(set! *warn-on-reflection* false )
9293
@@ -515,6 +516,25 @@ IOC and vthread code.
515516 (let [ret (impl/take! port (fn-handler nop false ))]
516517 (when ret @ret)))
517518
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))))
537+
518538(defmacro go
519539 " Asynchronously executes the body, returning immediately to the
520540 calling thread. Additionally, any visible calls to <!, >! and alt!/alts!
@@ -531,11 +551,11 @@ IOC and vthread code.
531551 Returns a channel which will receive the result of the body when
532552 completed"
533553 [& body]
534- (let [rt-check-step ( when clojure.core/*compile-files*
535- `(dispatch/ensure-runtime-vthreads!))]
536- ( if go-becomes-ioc?
537- ( do ( clojure.core.async.impl.dispatch/dynamic-require 'clojure.core.async.impl.go)
538- (( find-var 'clojure.core.async.impl.go/go-impl) &env body))
554+ (if go-becomes-ioc?
555+ ( do ( dynamic-require 'clojure.core.async.impl.go)
556+ (( 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!))]
539559 `(do ~rt-check-step
540560 (thread-call (^:once fn* [] ~@body) :io )))))
541561
0 commit comments