Skip to content

Commit

Permalink
refactor: use event emitter raw
Browse files Browse the repository at this point in the history
  • Loading branch information
Deivu committed Dec 22, 2024
1 parent f5111e5 commit e93bb74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/concurrency/AsyncQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ export declare interface AsyncQueueWaitOptions {
signal?: AbortSignal | undefined;
}

export declare interface AsyncQueueEmitter extends EventEmitter {
emit(event: string, args?: unknown): this;
on(event: 'resolve', listener: (message: string) => void): this;
once(event: 'resolve', listener: (message: string) => void): this;
off(event: 'resolve', listener: (event: unknown) => void): this;
}

export class AsyncQueue {
private readonly queue: AsyncQueueEmitter[];
private readonly queue: EventEmitter[];
constructor() {
this.queue = [];
}
Expand All @@ -25,7 +18,8 @@ export class AsyncQueue {
// @ts-expect-error: this is ok
const next = this.remaining ? once(this.queue[this.remaining - 1], 'resolve', { signal }) : Promise.resolve([]);

const emitter = new EventEmitter() as AsyncQueueEmitter;
const emitter = new EventEmitter();

this.queue.push(emitter);

if (signal) {
Expand All @@ -41,6 +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');
}
}
1 change: 1 addition & 0 deletions src/concurrency/ConcurrencyServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class ConcurrencyServer {
* @private
*/
private readonly password: string;

constructor(manager: Indomitable, concurrency: number) {
this.manager = manager;
this.server = Http.createServer((req, res) => this.handle(req, res));
Expand Down

0 comments on commit e93bb74

Please sign in to comment.