Skip to content

Commit

Permalink
Merge branch 'fix_perf_with_mutiple_connections' of https://github.co…
Browse files Browse the repository at this point in the history
…m/jezell/rete into jezell-fix_perf_with_mutiple_connections
  • Loading branch information
Ni55aN committed Oct 17, 2020
2 parents 6bdec4f + a405a21 commit 9d86615
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Engine extends Context<EventsTypes> {
args: unknown[] = [];
data: Data | null = null;
state = State.AVAILABLE;
forwarded = new Set();
onAbort = () => { };

constructor(id: string) {
Expand Down Expand Up @@ -156,15 +157,16 @@ export class Engine extends Context<EventsTypes> {
private async forwardProcess(node: NodeData) {
if (this.state === State.ABORT)
return null;

return await Promise.all(Object.keys(node.outputs).map(async (key) => {
const output = node.outputs[key];

return await Promise.all(output.connections.map(async (c) => {
const nextNode = (this.data as Data).nodes[c.node];

await this.processNode(nextNode as EngineNode);
await this.forwardProcess(nextNode);
if(!this.forwarded.has(nextNode)) {
this.forwarded.add(nextNode);
await this.processNode(nextNode as EngineNode);
await this.forwardProcess(nextNode);
}
}));
}));
}
Expand Down Expand Up @@ -225,10 +227,11 @@ export class Engine extends Context<EventsTypes> {

this.data = this.copy(data);
this.args = args;
this.forwarded = new Set();

await this.processStartNode(startId);
await this.processUnreachable();

return this.processDone()?'success':'aborted';
}
}
}

0 comments on commit 9d86615

Please sign in to comment.