Skip to content

Commit

Permalink
fix performance related issue where multiple connections results in e…
Browse files Browse the repository at this point in the history
…xponential amounts of work
  • Loading branch information
timu-jesse-ezell committed Jan 22, 2020
1 parent 18378c5 commit a405a21
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 a405a21

Please sign in to comment.