Loom.MVRegister

A causally consistent multi-value register.

A bit more causally rigorous than LWWRegister, MVRegister will replace observed values when they are set, but concurrent additions will co-occur, and a list will be returned for the value.

This is good if you have some reasonable way of figuring out how to resolve this further down your app keychain (including user resolution), but you can’t make it generic enough to work as a CRDT.

Summary

join(mvregister, mvregister)

Joins 2 MVRegisters

new()

Returns a new MVRegister CRDT

set(reg, actor, value)

Sets a value, erasing any current values

value(mvregister)

Returns the natural value of the register. If there is nothing, it’s nil. If it’s one thing, it’s that value (this is the normal case). If it’s more than one thing, all values are returned in a list

Types

actor :: term

t :: %Loom.MVRegister{set: Loom.AWORSet.t}

Functions

join(mvregister, mvregister)

Specs:

  • join(t, t) :: t

Joins 2 MVRegisters

iex> alias Loom.MVRegister, as: Reg
iex> {a, _} = Reg.new |> Reg.set(:a, "test") |> Reg.set(:a, "test2")
iex> {b, _} = Reg.new |> Reg.set(:b, "take over")
iex> Reg.join(a, b) |> Reg.value
["test2", "take over"]
new()

Specs:

  • new :: t

Returns a new MVRegister CRDT.

nil is a new CRDT’s identity value, and by default the system time in microseconds is used as the clock value.

iex> Loom.MVRegister.new |> Loom.MVRegister.value
nil
set(reg, actor, value)

Specs:

Sets a value, erasing any current values.

iex> alias Loom.MVRegister, as: Reg
iex> Reg.new
...> |> Reg.set(:a, "test")
...> |> Reg.set(:a, "test2")
...> |> Reg.value
"test2"
value(mvregister)

Specs:

  • value({t, t}) :: [term] | term | nil
  • value(t) :: [term] | term | nil

Returns the natural value of the register. If there is nothing, it’s nil. If it’s one thing, it’s that value (this is the normal case). If it’s more than one thing, all values are returned in a list.