1+
2+ ; ; Copyright (c) Rich Hickey and contributors. All rights reserved.
3+ ; ; The use and distribution terms for this software are covered by the
4+ ; ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5+ ; ; which can be found in the file epl-v10.html at the root of this distribution.
6+ ; ; By using this software in any fashion, you are agreeing to be bound by
7+ ; ; the terms of this license.
8+ ; ; You must not remove this notice, or any other, from this software.
9+
10+ (ns ^{:skip-wiki true }
11+ clojure.core.async.impl.dispatch
12+ (:require [clojure.core.async.impl.protocols :as impl]
13+ [clojure.core.async.impl.exec.threadpool :as tp]))
14+
15+ (set! *warn-on-reflection* true )
16+
17+ ; ;;(defonce ^:private in-dispatch (ThreadLocal.))
18+
19+ (defonce executor
20+ (delay (tp/thread-pool-executor ))) ; ;; #(.set ^ThreadLocal in-dispatch true) -- getting rid of this init-fn.
21+
22+ (defn in-dispatch-thread?
23+ " Returns true if the current thread is a go block dispatch pool thread"
24+ []
25+ false ) ; ;; we have no way to detect (boolean (.get ^ThreadLocal in-dispatch))
26+
27+ (defn check-blocking-in-dispatch
28+ " If the current thread is a dispatch pool thread, throw an exception"
29+ [] ; ;; making this a no-op
30+ ) ; ;; (when (.get ^ThreadLocal in-dispatch)
31+ ; ;; (throw (IllegalStateException. "Invalid blocking call in dispatch thread")))
32+
33+ (defn run
34+ " Runs Runnable r in a thread pool thread"
35+ [r] ; ;; ^Runnable -- we don't have this type. We are set up to take an IFn -- it will be called with no args
36+ (impl/exec @executor r))
0 commit comments