Skip to content

Commit

Permalink
Addressed icehaunter's review.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-dp committed Dec 13, 2023
1 parent 7ef93d2 commit 8a735a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion clients/typescript/src/util/asyncEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class AsyncEventEmitter<Events extends EventMap> {
// deep copy because once listeners mutate the `this.listeners` array as they remove themselves
// which breaks the `map` which iterates over that same array while the contents may shift
const ls = [...listeners]
const listenerProms = ls.map((listener) => listener(...args))
const listenerProms = ls.map(async (listener) => await listener(...args))

Promise
// wait for all listeners to finish,
Expand Down
28 changes: 8 additions & 20 deletions clients/typescript/test/util/asyncEventEmitter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,17 @@ test('test AsyncEventEmitter once listeners', async (t) => {
event: () => void | Promise<void>
}>()

let ctr = 0
const listener: () => void = () => t.pass()

const listener1 = () => {
ctr++
}

const listener2 = () => {
ctr++
}

const listener3 = () => {
ctr++
}

emitter.once('event', listener1)
emitter.once('event', listener2)
emitter.once('event', listener)
emitter.once('event', listener)
emitter.enqueueEmit('event')

emitter.once('event', listener3)
emitter.once('event', listener)
emitter.enqueueEmit('event')

await delay(100)
t.is(ctr, 3)
t.plan(3)
})

// Test that listeners can be prepended
Expand Down Expand Up @@ -103,9 +91,9 @@ test('test AsyncEventEmitter removeListener', async (t) => {
event: () => void | Promise<void>
}>()

let l1,
l2,
l3,
let l1 = false,
l2 = false,
l3 = false,
l4 = false

const listener1 = () => {
Expand Down

0 comments on commit 8a735a8

Please sign in to comment.