Skip to content

Commit

Permalink
Use forof instead of foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
yahgwai committed Aug 24, 2023
1 parent 3c8fda9 commit db4b217
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
11 changes: 4 additions & 7 deletions src-ts/proposalMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export abstract class ProposalMonitor extends EventEmitter {
return super.emit(eventName, args);
}

public override on(
eventName: TrackerEventName,
listener: (args: GPMEvent) => void
): this {
public override on(eventName: TrackerEventName, listener: (args: GPMEvent) => void): this {
return super.on(eventName, listener);
}

Expand All @@ -51,15 +48,15 @@ export abstract class ProposalMonitor extends EventEmitter {
this.pollingIntervalMs,
this.writeMode
);
AllTrackerEvents.forEach((ev) => {

for (const ev of AllTrackerEvents) {
tracker.on(ev, (args) => {
this.emit(ev, {
...args,
originAddress: this.originAddress,
});
});
});
}

tracker.run();
}
Expand Down
36 changes: 16 additions & 20 deletions src-ts/proposalPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface TrackerEvent {
stage: string;
prevStage?: Omit<TrackerEvent, "status">;
publicExecutionUrl?: string;
error?: Error
error?: Error;
}

export class StageTracker extends EventEmitter {
Expand All @@ -80,27 +80,11 @@ export class StageTracker extends EventEmitter {
return super.emit(eventName, args);
}

public override on(
eventName: TrackerEventName,
listener: (args: TrackerEvent) => void
): this {
public override on(eventName: TrackerEventName, listener: (args: TrackerEvent) => void): this {
return super.on(eventName, listener);
}

private propagateTrackerSubcriptions(tracker: StageTracker) {
// propagate events to the listener of this tracker - add some info about the previous stage
AllTrackerEvents.forEach((ev) => {
tracker.on(ev, (args) => {
this.emit(ev, {
...args,
prevStage: args.prevStage || {
stage: this.stage.name,
identifier: this.stage.identifier,
},
});
});
});
}
private propagateTrackerSubcriptions(tracker: StageTracker) {}

public async run() {
let polling = true;
Expand Down Expand Up @@ -145,7 +129,19 @@ export class StageTracker extends EventEmitter {
this.writeMode
);

this.propagateTrackerSubcriptions(tracker)
// propagate events to the listener of this tracker - add some info about the previous stage
for (const ev of AllTrackerEvents) {
tracker.on(ev, (args) => {
this.emit(ev, {
...args,
prevStage: args.prevStage || {
stage: this.stage.name,
identifier: this.stage.identifier,
},
});
});
}

// run but dont await
tracker.run();
}
Expand Down

0 comments on commit db4b217

Please sign in to comment.