0.1.1 • Published 22 days ago
@protocoldesigner-dev/protocol-executor v0.1.1
ProtocolExecutor TS
Typescript Executor for ProtocolDesigner
- Multiple stateful nodes
- Graphical edition
- Easy api
Installation & Usage
Install in your project:
$ npm install -D @protocoldesigner-dev/protocol-executor
Usge:
1.build and verify your protocol in the editor.
A traffic cross example:
2.initialize the protocol exported in json format:
const exec = new ProtocolExecutor(m);
3.register hook:
// do stop road H
function stopH(e :DefaultEvent, from :string, to :string){
console.log("stop road h");
console.log(e, from, to);
}
exec.registerHook({
node: 'H',
action: 'HS Stop'
}, stopH)
4.start the execution:
//You can also register hooks at INIT and START phases.
exec.init();
exec.start();
const events = [
{node: 'Traffic cross', action: 'VS Start'},
{node: 'Traffic cross', action: 'HL Start'},
{node: 'Traffic cross', action: 'VL Start'},
{node: 'Traffic cross', action: 'HS Start'},
]
//periodically issue events to simulate the traffic cross
var i=0;
setInterval(function(){
const t = exec.issueEvent(events[i++ % 4])
//wait for accepted or completed status.
t.accpeted().then((result)=>{...})
t.finished().then((result)=>{...})
}, 1000)
License
MIT.
TODO
- assertions.
- test specs.