| 48 | } |
| 49 | |
| 50 | setPriority(id: string, priority: number) { |
| 51 | // A dequeued item with the same id is no longer part of the queue. |
| 52 | const index = this.#queue.findIndex((element: Readonly<PriorityQueueOptions>, index) => index >= this.#head && element.id === id); |
| 53 | if (index === -1) { |
| 54 | throw new ReferenceError(`No promise function with the id "${id}" exists in the queue.`); |
| 55 | } |
| 56 | |
| 57 | const [item] = this.#queue.splice(index, 1); |
| 58 | this.enqueue(item!.run, {priority, id}); |
| 59 | } |
| 60 | |
| 61 | remove(id: string): void; |
| 62 | remove(run: RunFunction): void; |