Huakun Shen 6eeb228173
init
2025-01-18 03:58:42 -05:00

20 lines
363 B
TypeScript

type QPayload<T> = {
data: T;
timestamp: Date;
};
class Q<T> {
private queue: QPayload<T>[] = [];
constructor(private maxSize: number) {}
enqueue(item: T) {
if (this.queue.length >= this.maxSize) {
throw new Error("Queue is full");
}
this.queue.push({ data: item, timestamp: new Date() });
}
}