bs-hlc

0.1.1 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i bs-hlc

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

7.19 kB

Total Files

7

Last publish

Collaborators

  • paulshen