Skip to content

Commit

Permalink
vthread es when available
Browse files Browse the repository at this point in the history
  • Loading branch information
fogus committed Feb 26, 2025
1 parent c56fd02 commit 35e7ad9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/clojure/clojure/core/async/impl/dispatch.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,27 @@
[workflow]
(Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workflow) "-%d") true)))

(def virtual-threads-available?
(try
(Class/forName "java.lang.Thread$Builder$OfVirtual")
true
(catch ClassNotFoundException _
false)))

(defn- make-io-executor
[]
(if virtual-threads-available?
(-> (Thread/ofVirtual)
(Thread$Builder/.name "async-vthread-io-" 0)
.factory
Executors/newThreadPerTaskExecutor)
(make-ctp-named :io)))

(defn ^:private create-default-executor
[workload]
(case workload
:compute (make-ctp-named :compute)
:io (make-ctp-named :io)
:io (make-io-executor)
:mixed (make-ctp-named :mixed)))

(def executor-for
Expand Down

0 comments on commit 35e7ad9

Please sign in to comment.