Skip to content

Commit a4928ef

Browse files
committed
dispatch pool is io pool
1 parent 55cde2a commit a4928ef

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,8 @@
4444
any use of the async thread pool."
4545
(delay (or (Long/getLong "clojure.core.async.pool-size") 8)))
4646

47-
(defn thread-pool-executor
48-
([]
49-
(thread-pool-executor nil))
50-
([init-fn]
51-
(let [executor-svc (Executors/newFixedThreadPool
52-
@pool-size
53-
(counted-thread-factory "async-dispatch-%d" true
54-
{:init-fn init-fn}))]
55-
(reify impl/Executor
56-
(impl/exec [_ r]
57-
(.execute executor-svc ^Runnable r))))))
58-
5947
(defonce ^:private in-dispatch (ThreadLocal.))
6048

61-
(defonce executor
62-
(delay (thread-pool-executor #(.set ^ThreadLocal in-dispatch true))))
63-
6449
(defn in-dispatch-thread?
6550
"Returns true if the current thread is a go block dispatch pool thread"
6651
[]
@@ -84,15 +69,17 @@
8469
[workflow]
8570
(Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workflow) "-%d") true)))
8671

87-
(defn- default-construct-executor
88-
[workload]
89-
(case workload
90-
:compute (executor-ctor :compute)
91-
:io (executor-ctor :io)
92-
:mixed (executor-ctor :mixed)))
72+
(def ^:private default-construct-executor
73+
(memoize
74+
(fn [workload]
75+
(case workload
76+
:compute (executor-ctor :compute)
77+
:io (executor-ctor :io)
78+
:mixed (executor-ctor :mixed)
79+
:core-async-dispatch (default-construct-executor :io)))))
9380

9481
(defn construct-executor
95-
[workload]
82+
^ExecutorService [workload]
9683
(if-let [sysprop-ctor (when-let [esf (System/getProperty "clojure.core.async.executor-factory")]
9784
(requiring-resolve (symbol esf)))]
9885
(or (sysprop-ctor workload) (default-construct-executor workload))
@@ -108,6 +95,12 @@
10895
(let [^ExecutorService e (executor-for workload)]
10996
(.execute e r)))
11097

98+
(defonce executor
99+
(delay (let [executor-svc (construct-executor :core-async-dispatch)]
100+
(reify impl/Executor
101+
(impl/exec [_ r]
102+
(.execute executor-svc ^Runnable r))))))
103+
111104
(defn run
112105
"Runs Runnable r on current thread when :on-caller? meta true, else in a thread pool thread."
113106
[^Runnable r]

0 commit comments

Comments
 (0)