Skip to content

Commit

Permalink
wip: mimic Camunda Platform on inclusive gateway join
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Feb 6, 2022
1 parent 6a85b62 commit a30d5e7
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions lib/simulator/behaviors/InclusiveGatewayBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,25 @@ InclusiveGatewayBehavior.prototype.enter = function(context) {
parent: parentScope
} = scope;

const sameParentScopes = this._simulator.findScopes(scope => (
scope.parent === parentScope && scope.element !== element));

// There are still some tokens to wait for.
if (this._canReachAnyScope(sameParentScopes, element)) {
return;
}

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

for (const childScope of elementScopes) {
// Join if tokens waiting cover each incoming sequence flow.
if (elementScopes.length === incomingSequenceFlows.length) {
return this._join(context);
}

if (childScope !== scope) {
const sameParentScopes = this._simulator.findScopes(scope => (
scope.parent === parentScope && scope.element !== element));

// complete joining child scope
this._simulator.destroyScope(childScope.complete(), scope);
}
// There are still some tokens to wait for.
if (this._canReachAnyScope(sameParentScopes, element)) {
return;
}

this._simulator.exit(context);
this._join(context);
};

InclusiveGatewayBehavior.prototype.exit = function(context) {
Expand Down Expand Up @@ -89,6 +85,24 @@ InclusiveGatewayBehavior.prototype.exit = function(context) {
}
};

InclusiveGatewayBehavior.prototype._join = function(context) {
const elementScopes = this._simulator.findScopes({
parent: context.parent,
element: context.element
});

for (const childScope of elementScopes) {

if (childScope !== context.scope) {

// complete joining child scope
this._simulator.destroyScope(childScope.complete(), context.scope);
}
}

this._simulator.exit(context);
};

InclusiveGatewayBehavior.prototype._canReachAnyScope = function(scopes, currentElement, traversed = new Set()) {
if (traversed.has(currentElement)) {
return false;
Expand Down

0 comments on commit a30d5e7

Please sign in to comment.