Skip to content

Commit

Permalink
#208 - use enqueue function in setPriority
Browse files Browse the repository at this point in the history
  • Loading branch information
RaishavHanspal committed Jul 19, 2024
1 parent ccb7a53 commit 686f0d8
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions source/priority-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,7 @@ export default class PriorityQueue implements Queue<RunFunction, PriorityQueueOp
throw new Error('Undefined Item - No promise function of specified id available in the queue.');
}

item.priority = priority;
if (this.size === 0 || this.#queue[this.size - 1]!.priority! >= priority) {
this.#queue.push(item);
return;
}

const index = lowerBound(
this.#queue, item,
(a: Readonly<PriorityQueueOptions>, b: Readonly<PriorityQueueOptions>) => b.priority! - a.priority!,
);

this.#queue.splice(index, 0, item);
this.enqueue(item.run, {priority, id});
}

dequeue(): RunFunction | undefined {
Expand Down

0 comments on commit 686f0d8

Please sign in to comment.