Skip to content

Commit

Permalink
chore: review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 26, 2024
1 parent dde3752 commit a1bff7f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/timeline-state-resolver/src/waitGroup.ts
Original file line number Diff line number Diff line change
@@ -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<string, Map<number, ResolveFn>> = 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
Expand All @@ -15,11 +21,14 @@ export class WaitGroup {
}
}

async waitOnKey(portId: string, delay: number): Promise<boolean> {
let callbacks = this.#store.get(portId)
/**
* Wait for a key to be resolved (true), or timeout (false)
*/
async waitOnKey(key: string, delay: number): Promise<boolean> {
let callbacks = this.#store.get(key)
if (!callbacks) {
callbacks = new Map()
this.#store.set(portId, callbacks)
this.#store.set(key, callbacks)
}
const callbacks2 = callbacks

Expand Down

0 comments on commit a1bff7f

Please sign in to comment.