From aa9ce2ff6a8c603893d7cbde8662a74cfcd97fd2 Mon Sep 17 00:00:00 2001 From: Saya Date: Sun, 22 Dec 2024 18:15:27 +0800 Subject: [PATCH] fix: use NodeJS.EventEmitter for event emitter type --- src/concurrency/AsyncQueue.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/concurrency/AsyncQueue.ts b/src/concurrency/AsyncQueue.ts index 635dfa5..1404d3c 100644 --- a/src/concurrency/AsyncQueue.ts +++ b/src/concurrency/AsyncQueue.ts @@ -1,11 +1,11 @@ -import { EventEmitter, once } from 'events'; +import { EventEmitter, once } from 'node:events'; export declare interface AsyncQueueWaitOptions { signal?: AbortSignal | undefined; } export class AsyncQueue { - private readonly queue: EventEmitter[]; + private readonly queue: NodeJS.EventEmitter[]; constructor() { this.queue = []; } @@ -15,10 +15,10 @@ export class AsyncQueue { } public wait({ signal }: AsyncQueueWaitOptions): Promise { - // @ts-expect-error: this is ok + const next = this.remaining ? once(this.queue[this.remaining - 1], 'resolve', { signal }) : Promise.resolve([]); - const emitter = new EventEmitter(); + const emitter = new EventEmitter() as NodeJS.EventEmitter; this.queue.push(emitter); @@ -35,7 +35,7 @@ export class AsyncQueue { public shift(): void { const emitter = this.queue.shift(); - // @ts-expect-error: emit exists in event emitter + if (typeof emitter !== 'undefined') emitter.emit('resolve'); } }