Skip to main content

causal_key

Function causal_key 

Source
pub fn causal_key(event: &MeshEvent) -> (u64, StreamId, u64)
Expand description

The causal position of an event: its Lamport stamp, then its stream, then its sequence.

One definition, because every runtime must apply the same events in the same sequence for the fold to converge, and two comparators that drift apart would be two different states with one name. Collections key a BTreeMap by it rather than sorting themselves.

use majordomus_cli::mesh::journal::{causal_key, EventBody, Journal};
use majordomus_cli::mesh::identity::NodeIdentity;
use std::sync::Arc;

let j = Journal::open(Arc::new(NodeIdentity::ephemeral().unwrap()), "0000000000000001",
    "repo".into(), None).unwrap();
j.append_own(EventBody::SessionClosed { session: "s1".into() }).unwrap();
let event = &j.events()[0];
assert_eq!(causal_key(event), (event.lamport, event.stream.clone(), event.seq));