observed-remove-level

2.3.1 • Public • Published

Observed-Remove Set and Map

CircleCI npm version codecov

Eventually-consistent, conflict-free replicated data types (CRDT) implemented using LevelDB.

const os = require('os');
const path = require('path');
const uuid = require('uuid');
const level = require('level');
const { ObservedRemoveMap } = require('observed-remove-level');

const run = async () => {

  const location = path.join(os.tmpdir(), uuid.v4());
  const db = level(location, { valueEncoding: 'json' });

  const alice = new ObservedRemoveMap(db, [], {namespace:"alice" });
  const bob = new ObservedRemoveMap(db, [], {namespace:"bob" });

  alice.on('publish', (message) => {
    setTimeout(() => bob.process(message), Math.round(Math.random() * 1000));
  });

  bob.on('publish', (message) => {
    setTimeout(() => alice.process(message), Math.round(Math.random() * 1000));
  });

  await alice.set('a', 1);
  await bob.set('b', 2);

  // Later

  await alice.get('b'); // 2
  await bob.get('a'); // 1  
}

Install

yarn add observed-remove-level

Set API

Table of Contents

Map API

Table of Contents

Readme

Keywords

none

Package Sidebar

Install

npm i observed-remove-level

Weekly Downloads

4

Version

2.3.1

License

MIT

Unpacked Size

790 kB

Total Files

102

Last publish

Collaborators

  • bunchtogether