From db4b21739846079c46f1ebb7577cfdb07e91ccdd Mon Sep 17 00:00:00 2001 From: Chris Buckland Date: Thu, 24 Aug 2023 15:38:49 +0200 Subject: [PATCH] Use forof instead of foreach --- src-ts/proposalMonitor.ts | 11 ++++------- src-ts/proposalPipeline.ts | 36 ++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src-ts/proposalMonitor.ts b/src-ts/proposalMonitor.ts index 2266d023..3c8e5c1b 100644 --- a/src-ts/proposalMonitor.ts +++ b/src-ts/proposalMonitor.ts @@ -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); } @@ -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(); } diff --git a/src-ts/proposalPipeline.ts b/src-ts/proposalPipeline.ts index b5417a41..cb87cc09 100644 --- a/src-ts/proposalPipeline.ts +++ b/src-ts/proposalPipeline.ts @@ -63,7 +63,7 @@ export interface TrackerEvent { stage: string; prevStage?: Omit; publicExecutionUrl?: string; - error?: Error + error?: Error; } export class StageTracker extends EventEmitter { @@ -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; @@ -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(); }