From a62603c524a60e18b26b55d48151b1514927b15b Mon Sep 17 00:00:00 2001 From: Raishav Hanspal Date: Wed, 27 Nov 2024 18:10:35 +0530 Subject: [PATCH] match doc comment for .setPriority with readme --- source/index.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/source/index.ts b/source/index.ts index f34899b..9e9f35a 100644 --- a/source/index.ts +++ b/source/index.ts @@ -235,6 +235,36 @@ export default class PQueue '🦄', {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);