Skip to content

Commit

Permalink
match doc comment for .setPriority with readme
Browse files Browse the repository at this point in the history
  • Loading branch information
RaishavHanspal committed Nov 27, 2024
1 parent 52cbeef commit a62603c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,36 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
Updates the priority of a promise function by its id, affecting its execution order. Requires a defined concurrency limit to take effect.
For example, this can be used to prioritize a promise function to run earlier.
```js
import PQueue from 'p-queue';
const queue = new PQueue({concurrency: 1});
queue.add(async () => 'πŸ¦„', {priority: 1});
queue.add(async () => 'πŸ¦€', {priority: 0, id: 'πŸ¦€'});
queue.add(async () => 'πŸ¦„', {priority: 1});
queue.add(async () => 'πŸ¦„', {priority: 1});
queue.setPriority('πŸ¦€', 2);
```
In this case, the promise function with id: 'πŸ¦€' runs second.
You can also deprioritize a promise function to delay its execution:
```js
import PQueue from 'p-queue';
const queue = new PQueue({concurrency: 1});
queue.add(async () => 'πŸ¦„', {priority: 1});
queue.add(async () => 'πŸ¦€', {priority: 1, id: 'πŸ¦€'});
queue.add(async () => 'πŸ¦„');
queue.add(async () => 'πŸ¦„', {priority: 0});
queue.setPriority('πŸ¦€', -1);
```
Here, the promise function with id: 'πŸ¦€' executes last.
*/
setPriority(id: string, priority: number) {
this.#queue.setPriority(id, priority);
Expand Down

0 comments on commit a62603c

Please sign in to comment.