Ref Type: Agent

Overview

An agent is a reference type which is shared, asynchronous, and autonomous:

  • shared - multiple threads can share access

  • asynchronous - changes may not occur immediately

  • autonomous - changes are made to a single item

Example: Add 1 to foo, at some point in the future.

In Clojure (unlike Elixir's Actor-based simulation), agents are reactive: there is no imperative message loop and no blocking receive.

Clojure API

Note: "CC" links to the official Clojure documentation; "CD" links to ClojureDocs.

  • add-watch (CC, CD) - adds a watch function to an Agent

  • agent (CC, CD) - creates and returns an Agent

  • agent-error (CC, CD) - returns any exception thrown by an Agent

  • deref (CC, CD) - returns the current state of an Agent

  • restart-agent (CC, CD) - restarts a failing Agent

  • send (CC, CD) - dispatches an action to an Agent (thread pool)

  • send-off (CC, CD) - dispatches an action to an Agent (sep. thread)

  • set-validator! (CC, CD) - sets the validator-fn for an Agent

  • shutdown-agents (CC, CD) - shuts down the Agent system's thread pools

To be continued...


This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r6 - 21 Aug 2015, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email