https://github.com/lmatteis/behavioral
Behavioral Programming for JavaScript
https://github.com/lmatteis/behavioral
Last synced: 6 months ago
JSON representation
Behavioral Programming for JavaScript
- Host: GitHub
- URL: https://github.com/lmatteis/behavioral
- Owner: lmatteis
- License: mit
- Created: 2018-04-07T11:50:52.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-02-11T20:37:59.000Z (almost 7 years ago)
- Last Synced: 2025-04-11T00:05:09.374Z (9 months ago)
- Language: JavaScript
- Size: 136 KB
- Stars: 74
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - behavioral
README
```js
yarn add behavioral
```
```js
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();
```