Skip to content

Commit

Permalink
chore(simulator): refactor ParallelGatewayBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Aug 29, 2024
1 parent 19368b2 commit c6f00d2
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions lib/simulator/behaviors/ParallelGatewayBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,39 @@ export default function ParallelGatewayBehavior(

ParallelGatewayBehavior.prototype.enter = function(context) {

const {
scope
} = context;

const joiningScopes = this._findJoiningScopes(context);

if (joiningScopes.length) {

for (const childScope of joiningScopes) {

if (childScope !== scope) {

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

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

/**
* Find scopes that will be joined by this transition.
*
* @param {Object} enterContext
* @return {Scope[]} scopes joined by this transition
*/
ParallelGatewayBehavior.prototype._findJoiningScopes = function(enterContext) {

const {
scope,
element
} = context;
} = enterContext;

const sequenceFlows = filterSequenceFlows(element.incoming);

Expand All @@ -31,25 +60,17 @@ ParallelGatewayBehavior.prototype.enter = function(context) {
element: element
});

const finishedScopes = sequenceFlows
const matchingScopes = sequenceFlows
.map(
flow => elementScopes
.find(scope => scope.initiator.element === flow)
)
.filter(scope => scope);

if (finishedScopes.length === sequenceFlows.length) {

for (const childScope of finishedScopes) {

if (childScope !== scope) {

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

this._simulator.exit(context);
if (matchingScopes.length === sequenceFlows.length) {
return matchingScopes;
} else {
return [];
}
};

Expand Down

0 comments on commit c6f00d2

Please sign in to comment.