From a1bff7fc4bed4a8aabacb6f8b16675e7b7f1d5b8 Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Mon, 26 Aug 2024 14:23:53 +0100 Subject: [PATCH] chore: review comment --- packages/timeline-state-resolver/src/waitGroup.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/timeline-state-resolver/src/waitGroup.ts b/packages/timeline-state-resolver/src/waitGroup.ts index 58bb97ab3..a2619ff0b 100644 --- a/packages/timeline-state-resolver/src/waitGroup.ts +++ b/packages/timeline-state-resolver/src/waitGroup.ts @@ -1,9 +1,15 @@ type ResolveFn = (value: boolean) => void +/** + * A WaitGroup is used to wait for a number of operations to complete, or timeout + */ export class WaitGroup { #store: Map> = new Map() #nextId = 0 + /** + * Resolve all waiting operations for a key, with success + */ clearAllForKey(key: string): void { const callbacks = this.#store.get(key) if (!callbacks) return @@ -15,11 +21,14 @@ export class WaitGroup { } } - async waitOnKey(portId: string, delay: number): Promise { - let callbacks = this.#store.get(portId) + /** + * Wait for a key to be resolved (true), or timeout (false) + */ + async waitOnKey(key: string, delay: number): Promise { + let callbacks = this.#store.get(key) if (!callbacks) { callbacks = new Map() - this.#store.set(portId, callbacks) + this.#store.set(key, callbacks) } const callbacks2 = callbacks