Clojure: Transactions

By Xah Lee. Date: . Last updated: .

This page is WORK IN PROGRESS.

States, Transactions

refs
{synchronous, coordinated}. ref
agents
{asynchronous, independent}. agent
atoms
{synchronous, independent}. atom
var
like global var. def

“refs” is typical set variable.

(deref val) is same as @val

Transactions

“transactions” is like database transactions. Process inside a transaction happen together or not at all, there is no possibility of partial success. (this property is often called “atomicity”)

“transactions” are isolated. No 2 transactions see each other.

dosync creates a transaction. Other wise it's similar to do.

ref-set is for setting a ref. It can only be used within a transaction.

alter is like ref-set, except it takes a function and other args.

atom

atom is like ref, except it's rather for independent entities (update that do not need to be coordinated with others).

agents (asynchronous)

most useful.

thread-local state: var, def

validator and watch