ClojureDocs

Nav

Namespaces

send-via

clojure.core

Available since 1.5 (source)
  • (send-via executor a f & args)
Dispatch an action to an agent. Returns the agent immediately.
Subsequently, in a thread supplied by executor, the state of the agent
will be set to the value of:
 (apply action-fn state-of-agent args)
1 Example
;; "send" (FixedThreadPool) or "send-off" (CachedThreadPool) 
;; covers most of the thread pooling strategies.
;; But in case you want a different one, use "send-via" to pass
;; a different pool, for example ForkJoin.

(import '[java.util.concurrent Executors])
(def fj-pool (Executors/newWorkStealingPool))

(defn send-fj [^clojure.lang.Agent a f & args]
  (apply send-via fj-pool a f args))

(def a (agent 1))
(send-fj a inc)
(await a)
@a
;; 2
See Also

Dispatch an action to an agent. Returns the agent immediately. Subsequently, in a thread from a th...

Added by reborg

Dispatch a potentially blocking action to an agent. Returns the agent immediately. Subsequently, i...

Added by reborg
0 Notes
No notes for send-via