Giter VIP home page Giter VIP logo

compassion's Introduction

Actions Status codecov License: MIT

Paxos based consensus framework.

What Where
Discussion #1
Documentation https://bigeasy.github.io/compassion
Source https://github.com/bigeasy/compassion
Issues https://github.com/bigeasy/compassion/issues
CI https://travis-ci.org/bigeasy/compassion
Coverage: https://codecov.io/gh/bigeasy/compassion
License: MIT

Compassion installs from NPM.

npm install compassion

Living README.md

This README.md is also a unit test using the Proof unit test framework. We'll use the Proof okay function to assert out statements in the readme. A Proof unit test generally looks like this.

require('proof')(4, async okay => {
    okay('always okay')
    okay(true, 'okay if true')
    okay(1, 1, 'okay if equal')
    okay({ value: 1 }, { value: 1 }, 'okay if deep strict equal')
})

You can run this unit test yourself to see the output from the various code sections of the readme.

git clone [email protected]:bigeasy/compassion.git
cd compassion
npm install --no-package-lock --no-save
node test/readme.t.js

Overview

const Compassion = require('compassion')
const Destructible = require('destructible')
const { Queue } = require('avenue')
class KeyValueStore {
    constructor () {
        this.ready = new Promise(resolve => this.arrived = resolve)
        this.cookie = 0
        this.snapshots = {}
        this.resolutions = {}
        this.compassion = null
        this.store = null
    }

    initialize (compassion) {
        this.compassion = compassion
    }

    async bootstrap ({ self }) {
        this.promise = self.arrived
        this.store = {}
    }

    async snapshot ({ promise, queue }) {
        queue.push(this.snapshots[promise])
    }

    async join ({ self, shifter }) {
        this.promise = self.arrived
        this.store = await shifter.shift()
    }

    async arrive ({ arrival }) {
        this.arrived.call()
        this.snapshots[arrival.promise] = JSON.parse(JSON.stringify(this.store))
    }

    async acclimated ({ promise }) {
        this.snapshots[promise]
    }

    async entry ({ entry }) {
        this.store[entry.key] = entry.value
        const resolution = this.resolutions[entry.cookie]
        if (resolution != null) {
            delete this.resolutions[entry.cookie]
            resolution.call(null)
        }
    }

    async depart ({ promise }) {
        this.snapshots[promise]
    }

    set (key, value) {
        return new Promise(resolve => {
            const cookie = `${this.promise}?${this.cookie++}`
            this.resolutions[cookie] = resolve
            this.compassion.enqueue({ cookie, key, value })
        })
    }

    get (key) {
        return this.store[key]
    }
}
const destructible = new Destructible('compassion')

Construct a census. Usually you'll use Mingle, but we'll create a dummy census and fake the service discovery. We have to be sure to terminate the queue on shutdown, so we register a destruct handler.

const census = new Queue
destructible.destruct(() => census.push(null))
const kv = new KeyValueStore
const { address, port } = await Compassion.listen(destructible, {
    census: census.shifter(),
    applications: { kv },
    bind: { host: '127.0.0.1', port: 0 }
})
census.push([ `http://${address}:${port}` ])

await kv.ready
await kv.set('x', 1)
okay(kv.get('x'), 1, 'set and get')
destructible.destroy()

await destructible.promise

What do we need to discuss? Simple outline. Be sure to link to people to Conference. Uh, oh. I also have to document Mingle.

Initialize

Bootstrap

Join and Snapshot

Arrive

Acclimated

Entry

Depart

compassion's People

Contributors

flatheadmill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

compassion's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.