File tree 1 file changed +27
-17
lines changed
src/main/clojure/clojure/core/async/impl
1 file changed +27
-17
lines changed Original file line number Diff line number Diff line change 80
80
(.uncaughtException (Thread/currentThread ) ex))
81
81
nil )
82
82
83
- (defonce ^ExecutorService mixed-executor
84
- (Executors/newCachedThreadPool (counted-thread-factory " async-mixed-%d" true )))
85
-
86
- (defonce ^ExecutorService io-executor
87
- (Executors/newCachedThreadPool (counted-thread-factory " async-io-%d" true )))
88
-
89
- (defonce ^ExecutorService compute-executor
90
- (Executors/newCachedThreadPool (counted-thread-factory " async-compute-%d" true )))
83
+ (def construct-es
84
+ (let [esf (System/getProperty " clojure.core.async.esfactory" )]
85
+ (or
86
+ (and esf (requiring-resolve (symbol esf)))
87
+ (fn [workload]
88
+ (case workload
89
+ :compute (Executors/newCachedThreadPool (counted-thread-factory " async-compute-%d" true ))
90
+ :io (Executors/newCachedThreadPool (counted-thread-factory " async-io-%d" true ))
91
+ :mixed (Executors/newCachedThreadPool (counted-thread-factory " async-mixed-%d" true ))
92
+ (throw (IllegalArgumentException. (str " Illegal workload tag " workload))))))))
93
+
94
+ (defonce ^ExecutorService mixed-executor (construct-es :mixed ))
95
+
96
+ (defonce ^ExecutorService io-executor (construct-es :io ))
97
+
98
+ (defonce ^ExecutorService compute-executor (construct-es :compute ))
99
+
100
+ (defn es-for [workload]
101
+ (case workload
102
+ :compute compute-executor
103
+ :io io-executor
104
+ :mixed mixed-executor
105
+ nil ))
91
106
92
107
(defn exec
93
- [^Runnable r exec]
94
- (let [^ExecutorService e (case exec
95
- :compute compute-executor
96
- :io io-executor
97
- :mixed mixed-executor
98
- nil )]
99
- (if e
100
- (.execute e r)
101
- (impl/exec @executor r))))
108
+ [^Runnable r workload]
109
+ (if-let [^ExecutorService e (es-for workload)]
110
+ (.execute e r)
111
+ (impl/exec @executor r)))
102
112
103
113
(defn run
104
114
" Runs Runnable r on current thread when :on-caller? meta true, else in a thread pool thread."
You can’t perform that action at this time.
0 commit comments