Mar 3, 2016
Index of all namespaces
Asynchronous Agents Using Manifold
Create an asynchronous agent:
(require '[com.joshuagriffith.async-agent :as a]) (def val (a/async-agent 42))
Asynchronous agents also optionally take a queue buffer size:
(def val (a/async-agent 42 2))
Asynchronous agents return a Manifold deferred representing the value of the agent after the operation has been completed:
(a/async-send val inc) ;; => << 43 >> @val ;; => 43
If an exception is thrown, the agent value will not be updated and the exception will be available in the deferred:
@(a/async-send val / 0) ;; => ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:158) @val ;; => 43
The function provided to
async-send can return any type that can be coerced by Manifold:
@(a/async-send val #(future (Thread/sleep 1000) (inc %))) ;; => 44
Copyright © 2015 Joshua Griffith.
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.