0.1.1 • Published 4 years ago

bs-hlc v0.1.1

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

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.