|
23 | 23 | (defonce io-exec clojure.lang.Agent/soloExecutor)
|
24 | 24 | (defonce compute-exec clojure.lang.Agent/pooledExecutor)
|
25 | 25 |
|
26 |
| -(defn oid [x] |
27 |
| - (symbol (str (-> x class .getSimpleName) "@" (-> x System/identityHashCode Integer/toHexString)))) |
28 |
| - |
29 |
| -(defn chan->data |
30 |
| - [^clojure.core.async.impl.channels.ManyToManyChannel c] |
31 |
| - (let [b (.buf c)] |
32 |
| - {:buffer (if (some? b) (oid b) :none) |
33 |
| - :buffer-count (count b) |
34 |
| - :put-count (count (.puts c)) |
35 |
| - :take-count (count (.takes c)) |
36 |
| - :closed? (clojure.core.async.impl.protocols/closed? c)})) |
37 |
| - |
38 |
| -(defn exec->data [exec] |
39 |
| - (let [ess (as-> (str exec) ^String es |
40 |
| - (.substring es (inc (.lastIndexOf es "[")) (.lastIndexOf es "]")) |
41 |
| - (.split es ","))] |
42 |
| - (merge {:id (oid exec) |
43 |
| - :status (first ess)} ;;TODO less fragile |
44 |
| - (zipmap [:pool-size :active-threads :queued-tasks :completed-tasks] |
45 |
| - (map #(-> ^String % (.substring (inc (.lastIndexOf ^String % " "))) Long.) (rest ess)))))) |
46 |
| - |
47 | 26 | (defn datafy [x]
|
48 | 27 | (condp instance? x
|
49 | 28 | clojure.lang.Fn (-> x str symbol)
|
50 |
| - ExecutorService (exec->data x) |
| 29 | + ExecutorService (str x) |
51 | 30 | clojure.lang.Var (symbol x)
|
52 |
| - clojure.core.async.impl.channels.ManyToManyChannel (chan->data x) |
53 | 31 | (datafy/datafy x)))
|
54 | 32 |
|
55 | 33 | (defn futurize ^Future [f {:keys [exec]}]
|
|
242 | 220 | (loop [nstatus nstatus, nstate nstate, msgs (seq msgs)]
|
243 | 221 | (if (or (nil? msgs) (= nstatus :exit))
|
244 | 222 | [nstatus nstate]
|
245 |
| - (let [m (if-some [m (first msgs)] m (throw (Exception. "messages must be non-nil"))) |
246 |
| - [v c] (async/alts!! |
247 |
| - [control [outc m]] |
| 223 | + (let [[v c] (async/alts!! |
| 224 | + [control [outc (first msgs)]] |
248 | 225 | :priority true)]
|
249 | 226 | (if (= c control)
|
250 | 227 | (let [nnstatus (handle-command nstatus v)
|
|
0 commit comments