observed-remove-level
v2.3.1
Published
[![CircleCI](https://circleci.com/gh/wehriam/observed-remove-level.svg?style=svg)](https://circleci.com/gh/wehriam/observed-remove-level) [![npm version](https://badge.fury.io/js/observed-remove-level.svg)](http://badge.fury.io/js/observed-remove-level) [
Downloads
2
Readme
Observed-Remove Set and Map
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