From a30d5e76738fa28d2de33eb8bde2b5f883da6521 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Sun, 6 Feb 2022 01:38:35 +0100 Subject: [PATCH] wip: mimic Camunda Platform on inclusive gateway join --- .../behaviors/InclusiveGatewayBehavior.js | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/simulator/behaviors/InclusiveGatewayBehavior.js b/lib/simulator/behaviors/InclusiveGatewayBehavior.js index fa8c1239..d63e4d4c 100644 --- a/lib/simulator/behaviors/InclusiveGatewayBehavior.js +++ b/lib/simulator/behaviors/InclusiveGatewayBehavior.js @@ -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) { @@ -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;