'use strict';
const Bpmn = require('bpmn-engine');
const EventEmitter = require('events').EventEmitter;
const fs = require('fs');
let enginestate = null;
// const processXml = fs.readFileSync(__dirname + '/resources/parallel-gateway.bpmn', 'utf-8');
const processXml = `
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.6.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_0lb50jr</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_0lb50jr" sourceRef="StartEvent_1" targetRef="ExclusiveGateway_1huvwfm" />
<bpmn:parallelGateway id="ExclusiveGateway_1huvwfm">
<bpmn:incoming>SequenceFlow_0lb50jr</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1t5xyuf</bpmn:outgoing>
<bpmn:outgoing>SequenceFlow_0sb9gi3</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:sequenceFlow id="SequenceFlow_1t5xyuf" sourceRef="ExclusiveGateway_1huvwfm" targetRef="t_a" />
<bpmn:sequenceFlow id="SequenceFlow_0sb9gi3" sourceRef="ExclusiveGateway_1huvwfm" targetRef="t_b" />
<bpmn:sequenceFlow id="SequenceFlow_167zujm" sourceRef="t_b" targetRef="ExclusiveGateway_0xb7xzm" />
<bpmn:parallelGateway id="ExclusiveGateway_0xb7xzm">
<bpmn:incoming>SequenceFlow_167zujm</bpmn:incoming>
<bpmn:incoming>SequenceFlow_0ombfuh</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_00feimj</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:sequenceFlow id="SequenceFlow_0ombfuh" sourceRef="t_a" targetRef="ExclusiveGateway_0xb7xzm" />
<bpmn:userTask id="t_a" name="task a">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="a" type="string" />
</camunda:formData>
<camunda:inputOutput>
<camunda:outputParameter name="m_a">
<camunda:script scriptFormat="javascript">this.a</camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_1t5xyuf</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0ombfuh</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="t_b" name="task b">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="b" type="string" />
</camunda:formData>
<camunda:inputOutput>
<camunda:outputParameter name="m_b">
<camunda:script scriptFormat="javascript">this.b</camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_0sb9gi3</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_167zujm</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="SequenceFlow_00feimj" sourceRef="ExclusiveGateway_0xb7xzm" targetRef="t_c" />
<bpmn:endEvent id="EndEvent_138frla">
<bpmn:incoming>SequenceFlow_092u6ac</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_092u6ac" sourceRef="t_c" targetRef="EndEvent_138frla" />
<bpmn:userTask id="t_c" name="task c">
<bpmn:incoming>SequenceFlow_00feimj</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_092u6ac</bpmn:outgoing>
</bpmn:userTask>
</bpmn:process>
</bpmn:definitions>
`;
const engine = new Bpmn.Engine({
name: 'user task example 1',
moddleOptions: {
camunda: require('camunda-bpmn-moddle/resources/camunda')
},
source: processXml
});
const listener = new EventEmitter();
listener.on('wait-t_a', (child, instance) => {
// console.log(engine.getState());
// instance.signal(child.activity.id, {
// a: 'aaaaaaaaaaaa'
// });
});
listener.on('wait-t_b', (child, instance) => {
// console.log(engine.getState());
// instance.signal(child.activity.id, {
// b: 'bbbbbbbbbbbbb'
// });
});
engine.on('end', (task, instance) => {
console.log(`engine is completed`);
});
engine.execute({
listener: listener
}, (err, instance) => {
if (err) throw err;
});
setTimeout(function () {
enginestate = engine.getState();
console.log(enginestate);
let listener_1 = new EventEmitter();
let engine_1 = Bpmn.Engine.resume(enginestate, {
listener: listener_1
});
listener_1.on('wait-t_b', (task, instance) => {
// console.log(engine_1.getState());
let pendings = engine_1.getPendingActivities();
console.log(pendings.definitions[0]);
// instance.signal(task.activity.id, {
// b: 'aaaaaaaaaaaaaa'
// });
});
listener_1.on('wait-t_a', (task, instance) => {
// console.log(engine_1.getState());
let pendings = engine_1.getPendingActivities();
console.log(pendings.definitions[0]);
// instance.signal(task.activity.id, {
// a: 'aaaaaaaaaaaaaa'
// });
});
listener_1.on('wait-t_c', (task, instance) => {
console.log('wait t_c');
let pendings = engine_1.getPendingActivities();
console.log(pendings.definitions[0]);
})
engine_1.on('end', (task, instance) => {
console.log(`engine is end`);
})
}, 2000);