Giter Club home page Giter Club logo

cocktail-control's Introduction

cocktail-control  Build Status

The control logic for some bots that makes cocktail

Install

npm i level @matteo.collina/cocktail-control --save

Example

var level = require('level')
var control = require('@matteo.collina/cocktail-control')
var cocktails = {
  bloody: {
    activations: [
      20, // milleseconds
      10,
      50
    ]
  },
  spritz: {
    activations: [
      10, // milleseconds
      20,
      30
    ]
  }
}
var defs = {
  cocktails: cocktails,
  workers: {
    bob: {
      cocktails: ['bloody', 'spritz']
    },
    mark: {
      cocktails: ['spritz', 'spritz']
    }
  }
}

// the leveldb is used for persitence
var db = level(dir.name)
var robot = control(db, defs)

// enqueue also accepts a callback
robot.enqueue({
  cocktail: 'spritz',
  name: 'Matteo'
}).enqueue({
  cocktail: 'spritz',
  name: 'Cian'
}).enqueue({
  cocktail: 'spritz',
  name: 'Tammy'
}).enqueue({
  cocktail: 'bloody',
  name: 'David'
}).enqueue({
  cocktail: 'bloody',
  name: 'Richard'
})

robot.on('bob', function (cocktails) {
  console.log('bob making', cocktails)

  // this would be async in the real world
  setImmediate(robot.free.bind(robot, 'bob'))
})

robot.on('mark', function (cocktails) {
  console.log('mark making', cocktails)

  // this would be async in the real world
  setImmediate(robot.free.bind(robot, 'mark'))
})

// kick off processing of cocktails
robot.free('bob') // let says that bob is free
robot.free('mark') // let says that mark is free

Acknowledgements

This library was built for NodeConf.eu, and it was sponsored by nearForm

License

MIT

cocktail-control's People

Contributors

mcollina avatar

Watchers

 avatar  avatar  avatar

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.