Skip to content

Commit

Permalink
chore: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Aug 29, 2024
1 parent 3982439 commit ecfaba1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
57 changes: 23 additions & 34 deletions lib/simulator/behaviors/ParallelGatewayBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,39 @@ export default function ParallelGatewayBehavior(
simulator.registerBehavior('bpmn:ParallelGateway', this);
}

var incomingToken = [];

ParallelGatewayBehavior.prototype.enter = function(context) {

const incomingFlows = filterSequenceFlows(context.scope.element.incoming);

if (incomingFlows.length < 2) {
const {
scope,
element
} = context;

// fork-only gateways are activated immediately
this._simulator.exit(context);
return;
}
const sequenceFlows = filterSequenceFlows(element.incoming);

const arrivingToken = {
source: context.source,
scope: context.scope
};
incomingToken.push(arrivingToken);
const {
parent: parentScope
} = scope;

var consumableToken = [];
const elementScopes = this._simulator.findScopes({
parent: parentScope,
element: element
});

for (const flow of incomingFlows) {
const waitingToken = incomingToken.filter(t => {
return (
t.source === flow &&
t.scope.initiator === context.scope.initiator
);
});
const finishedScopes = sequenceFlows
.map(
flow => elementScopes
.find(scope => scope.initiator.element === flow)
)
.filter(scope => scope);

if (waitingToken.length !== 0) {
if (finishedScopes.length === sequenceFlows.length) {

// only one token per incoming flow is consumed on join
consumableToken.push(waitingToken[0]);
} else {
break;
}
}
for (const childScope of finishedScopes) {

if (consumableToken.length === incomingFlows.length) {
for (const consumedToken of consumableToken) {
incomingToken.splice(incomingToken.indexOf(consumedToken), 1);
if (childScope !== scope) {

if (consumedToken.scope !== context.scope) {
this._simulator.destroyScope(consumedToken.scope.complete(), context.scope);
// complete joining child scope
this._simulator.destroyScope(childScope.complete(), scope);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/simulator/behaviors/SequenceFlowBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SequenceFlowBehavior.prototype.exit = function(context) {
} = context;

this._simulator.enter({
source: element,
initiator: scope,
element: element.target,
scope: scope.parent
});
Expand Down

0 comments on commit ecfaba1

Please sign in to comment.