bs-hlc
v0.1.1
Published
[Hybrid Logical Clocks](https://muratbuffalo.blogspot.com/2014/07/hybrid-logical-clocks.html) implemented in Reason/BuckleScript.
Downloads
2
Readme
bs-hlc
Hybrid Logical Clocks implemented in Reason/BuckleScript.
Installation
npm install --save bs-hlc
or
yarn add bs-hlc
In your bsconfig.json
, include "bs-hlc"
in the bs-dependencies
.
Usage
let myClock = ref(HLC.make(~node="myNodeId"));
type message = {
content: string,
clock: string, // serialized HLC
};
let sendMessage = (content) => {
myClock := HLC.increment(myClock^);
let message = {
content,
clock: HLC.toString(myClock^),
};
};
let receiveMessage = remoteMessage => {
myClock :=
HLC.receive(
myClock^,
HLC.fromString(remoteMessage.clock) |> Belt.Option.getExn,
);
};
Credits
This is a BuckleScript port of jlongster's timestamp.js and jaredly's hlc.js.