@@ -17,11 +17,11 @@ go block threads - use Thread.setDefaultUncaughtExceptionHandler()
1717to catch and handle.
1818
1919Use the Java system property `clojure.core.async.executor-factory`
20- to specify a function that will provide ExecutorServices for
20+ to specify a function that will provide an Executor instance for
2121application-wide use by core.async in lieu of its defaults. The
2222property value should name a fully qualified var. The function
2323will be passed a keyword indicating the context of use of the
24- executor, and should return either an ExecutorService , or nil to
24+ executor, and should return either an Executor , or nil to
2525use the default. Results per keyword will be cached and used for
2626the remainder of the application. Possible context arguments are:
2727
@@ -36,7 +36,7 @@ flow/process
3636
3737:core-async-dispatch - used for completion fn handling (e.g. in put!
3838and take!, as well as go block IOC thunk processing) throughout
39- core.async. If not supplied the ExecutorService for :io will be
39+ core.async. If not supplied, the Executor for :io will be
4040used instead.
4141
4242The set of contexts may grow in the future so the function should
@@ -49,14 +49,23 @@ return nil for unexpected contexts."
4949 [clojure.core.async.impl.timers :as timers]
5050 [clojure.core.async.impl.dispatch :as dispatch]
5151 [clojure.core.async.impl.ioc-macros :as ioc]
52- clojure.core.async.impl.go ; ; TODO: make conditional
5352 [clojure.core.async.impl.mutex :as mutex]
5453 )
5554 (:import [java.util.concurrent.atomic AtomicLong]
5655 [java.util.concurrent.locks Lock]
5756 [java.util.concurrent ThreadLocalRandom]
5857 [java.util Arrays ArrayList]))
5958
59+ (defn- at-least-clojure-version?
60+ [[maj min incr]]
61+ (let [{:keys [major minor incremental]} *clojure-version*]
62+ (not (neg? (compare [major minor incremental] [maj min incr])))))
63+
64+ (def ^:private lazy-loading-supported? (at-least-clojure-version? [1 12 3 ]))
65+
66+ (when-not lazy-loading-supported?
67+ (require 'clojure.core.async.impl.go))
68+
6069(alias 'core 'clojure.core)
6170
6271(set! *warn-on-reflection* false )
@@ -485,9 +494,13 @@ return nil for unexpected contexts."
485494 core.async blocking ops (those ending in !!) and other blocking IO.
486495
487496 Returns a channel which will receive the result of the body when
488- completed"
497+ completed.
498+
499+ The resources associated with a go block may be reclaimed, and the block
500+ never resumed, when the channels with which it interacts are no longer
501+ referenced (outside of the go block)."
489502 [& body]
490- (# 'clojure.core.async.impl.go/go-impl &env body))
503+ (( requiring-resolve 'clojure.core.async.impl.go/go-impl) &env body))
491504
492505(defonce ^:private thread-macro-executor nil )
493506
@@ -524,7 +537,12 @@ return nil for unexpected contexts."
524537 " Executes the body in a thread, returning immediately to the calling
525538 thread. The body may do blocking I/O but must not do extended computation.
526539 Returns a channel which will receive the result of the body when completed,
527- then close."
540+ then close.
541+
542+ Will dispatch to a virtual thread if available in the runtime JVM, and an
543+ ordinary thread if not. Like 'thread's (and unlike 'go' blocks) 'io-thread's
544+ must terminate ordinarily, and will keep referenced resources alive
545+ until they do."
528546 [& body]
529547 `(thread-call (^:once fn* [] ~@body) :io ))
530548
0 commit comments