Skip to content

Commit c365f93

Browse files
committed
names
1 parent 652f482 commit c365f93

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
(set! *warn-on-reflection* true)
1515

16+
(defonce ^:private in-dispatch (ThreadLocal.))
17+
18+
(defonce executor nil)
19+
1620
(defn counted-thread-factory
1721
"Create a ThreadFactory that maintains a counter for naming Threads.
1822
name-format specifies thread names - use %d to include counter
@@ -44,8 +48,6 @@
4448
any use of the async thread pool."
4549
(delay (or (Long/getLong "clojure.core.async.pool-size") 8)))
4650

47-
(defonce ^:private in-dispatch (ThreadLocal.))
48-
4951
(defn in-dispatch-thread?
5052
"Returns true if the current thread is a go block dispatch pool thread"
5153
[]
@@ -65,25 +67,25 @@
6567
(.uncaughtException (Thread/currentThread) ex))
6668
nil)
6769

68-
(defn- executor-ctor
70+
(defn- make-ctp-named
6971
[workflow]
7072
(Executors/newCachedThreadPool (counted-thread-factory (str "async-" (name workflow) "-%d") true)))
7173

72-
(def ^:private default-construct-executor
74+
(def ^:private default-executor-factory
7375
(memoize
7476
(fn [workload]
7577
(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)))))
78+
:compute (make-ctp-named :compute)
79+
:io (make-ctp-named :io)
80+
:mixed (make-ctp-named :mixed)
81+
:core-async-dispatch (make-ctp-named :io)))))
8082

8183
(defn construct-executor
8284
^ExecutorService [workload]
8385
(if-let [sysprop-ctor (when-let [esf (System/getProperty "clojure.core.async.executor-factory")]
8486
(requiring-resolve (symbol esf)))]
85-
(or (sysprop-ctor workload) (default-construct-executor workload))
86-
(default-construct-executor workload)))
87+
(or (sysprop-ctor workload) (default-executor-factory workload))
88+
(default-executor-factory workload)))
8789

8890
(defn executor-for [workload]
8991
(case workload
@@ -96,16 +98,9 @@
9698
(let [^ExecutorService e (executor-for workload)]
9799
(.execute e r)))
98100

99-
(defonce executor
100-
(delay (let [^ExecutorService executor-svc (construct-executor :core-async-dispatch)]
101-
(reify impl/Executor
102-
(impl/exec [_ r]
103-
(.execute executor-svc ^Runnable r))))))
104-
105101
(defn run
106102
"Runs Runnable r on current thread when :on-caller? meta true, else in a thread pool thread."
107103
[^Runnable r]
108104
(if (-> r meta :on-caller?)
109105
(try (.run r) (catch Throwable t (ex-handler t)))
110-
(impl/exec @executor r)))
111-
106+
(exec r :io)))

0 commit comments

Comments
 (0)