lux/concurrency/atom

Types

Atom

Atomic references that are safe to mutate concurrently.

(type: (Atom a)
  ((All [b] (host java.util.concurrent.atomic.AtomicReference c)) a))

Values

(atom value)

(All [a] (-> a (Atom a)))

(compare-and-swap current new atom)

Only mutates an atom if you can present it's current value.

That guarantees that atom wasn't updated since you last read from it.

(All [a] (-> a a (Atom a) (lux/codata/io;IO lux;Bool)))

(get atom)

(All [a] (-> (Atom a) (lux/codata/io;IO a)))

(set value atom)

(All [a] (-> a (Atom a) (lux/codata/io;IO lux;Unit)))

(update f atom)

Updates an atom by applying a function to its current value.

If it fails to update it (because some other process wrote to it first), it will retry until it succeeds.

The retries will be done with the new values of the atom, as they show up.

(All [a] (-> (-> a a) (Atom a) (lux/codata/io;IO lux;Unit)))