24 lines
578 B
TypeScript
24 lines
578 B
TypeScript
|
|
import { Injectable } from '@nestjs/common';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class QueueService {
|
||
|
|
private queues: Map<string, any[]> = new Map();
|
||
|
|
|
||
|
|
add(queueName: string, data: any) {
|
||
|
|
if (!this.queues.has(queueName)) {
|
||
|
|
this.queues.set(queueName, []);
|
||
|
|
}
|
||
|
|
this.queues.get(queueName)!.push(data);
|
||
|
|
}
|
||
|
|
|
||
|
|
async processNext(queueName: string): Promise<any | null> {
|
||
|
|
const queue = this.queues.get(queueName);
|
||
|
|
if (!queue || queue.length === 0) return null;
|
||
|
|
return queue.shift();
|
||
|
|
}
|
||
|
|
|
||
|
|
getQueueNames(): string[] {
|
||
|
|
return Array.from(this.queues.keys());
|
||
|
|
}
|
||
|
|
}
|