Skip to content
Behavioral Programming for JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Add priority field to .lastEvent Feb 11, 2019
.babelrc Add tests Oct 19, 2018
.gitignore v1.0.0 Oct 19, 2018
.prettierignore Add tests Oct 19, 2018
.prettierrc Refactor as library Oct 19, 2018
LICENSE Initial commit Apr 7, 2018
README.md Update README Oct 19, 2018
index.js Add priority field to .lastEvent Feb 11, 2019
package.json Add priority field to .lastEvent Feb 11, 2019

README.md

yarn add behavioral
import BProgram from 'behavioral';

const bp = new BProgram();
let priority = 0;

bp.addBThread('Add hot water 3 times', ++priority, function*() {
  yield {
    request: 'HOT'
  };
  yield {
    request: 'HOT'
  };
  yield {
    request: 'HOT'
  };
});

bp.addBThread('Add cold water 3 times', ++priority, function*() {
  yield {
    request: 'COLD'
  };
  yield {
    request: 'COLD'
  };
  yield {
    request: 'COLD'
  };
});

bp.addBThread('Interleave', ++priority, function*() {
  while (true) {
    yield {
      wait: 'HOT',
      block: 'COLD'
    };
    yield {
      wait: 'COLD',
      block: 'HOT'
    };
  }
});

bp.addBThread('console.log', ++priority, function*() {
  while (true) {
    yield {
      wait: () => true
    };
    console.log(this.lastEvent());
  }
});

bp.run();
You can’t perform that action at this time.