CrossClj

0.2.0 docs

SourceDocs


project

docs index

NAMESPACES
com.joshuagriffith

RECENT

    async-agent

    Clojars

    Mar 3, 2016


    OWNER
    Joshua Griffith
    Wilton, CT
    contact@joshuagriffith.com
    keybase.io/joshua

    Readme

    Index of all namespaces


    The README below is fetched from the published project artifact. Some relative links may be broken.

    async-agent

    Provides asynchronous agents using Manifold.

    Clojars Project

    Usage

    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
    

    License

    Copyright © 2015 Joshua Griffith.

    Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.