Skip to content

Commit

Permalink
make duplicate ids impossible
Browse files Browse the repository at this point in the history
  • Loading branch information
nullsoepic committed Sep 24, 2024
1 parent 8503713 commit 1c6c3ca
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export class PriorityQueue<T> {
id: string
): Promise<T> {
return new Promise((resolve, reject) => {
if (this.isProcessingOrQueued(id)) {
reject(new Error(`Task ${id} is already being processed`));
}
this.queue.push({ fn, args, priority, id, resolve, reject });
this.queue.sort((a, b) => b.priority - a.priority);
this.processNextItem();
Expand Down

0 comments on commit 1c6c3ca

Please sign in to comment.