lww_register
The last-write-wins register CRDT.
CRDTs (conflict-free replicated data type) are data structures that can be can be merged in any order and always get the same result at the end. They may be useful for making distributed programs where not all the nodes are able to co-ordinate to change agree on program state.
Types
A CRDT that is container for a single value.
It also contains a timestamp of the last change, and an id for the node in the distributed program that last set the value. This id might be the computer hostname or some other unique id.
This type is not opaque, but you should prefer using the functions provided to interact with it rather than modifying the values directly.
pub type LWWRegister(value) {
LWWRegister(value: value, timestamp: Int, id: String)
}
Constructors
-
LWWRegister(value: value, timestamp: Int, id: String)
Functions
pub fn merge(
left: LWWRegister(a),
right: LWWRegister(a),
) -> LWWRegister(a)
Merge to registers together.
Whichever register has the highest timestamp will be the one whose value remains after the merge.
In the event that both timestamps are the same the one with the greater id is used.
pub fn new(value value: a, local_id id: String) -> LWWRegister(a)
Create a new register with the given value, for the given id.