client-run-queue
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -13,2 +13,5 @@ import type { RunQueueEntry } from './types/entry'; | ||
private processingCount; | ||
/** The delayed entries that haven't been scheduled yet */ | ||
private readonly delayedEntries; | ||
/** The priority queue of scheduled entries, not including delayed entries */ | ||
private readonly heap; | ||
@@ -22,3 +25,6 @@ /** | ||
readonly cancelAll: () => void; | ||
/** Gets the total queue length, which may include canceled entries that haven't been purged yet */ | ||
/** | ||
* Gets the total queue length, which may include canceled entries that haven't been purged yet and delayed entries that aren't yet | ||
* ready for execution | ||
*/ | ||
readonly getQueueLength: () => number; | ||
@@ -25,0 +31,0 @@ /** |
@@ -21,2 +21,3 @@ "use strict"; | ||
const consts_2 = require("./internal/consts"); | ||
const DoubleLinkedList_1 = require("./internal/DoubleLinkedList"); | ||
class RunQueue { | ||
@@ -33,2 +34,5 @@ // Constructor | ||
this.processingCount = 0; | ||
/** The delayed entries that haven't been scheduled yet */ | ||
this.delayedEntries = new DoubleLinkedList_1.DoubleLinkedList(); | ||
/** The priority queue of scheduled entries, not including delayed entries */ | ||
this.heap = new heap_1.default((a, b) => a.priority - b.priority); | ||
@@ -40,2 +44,8 @@ // Public Methods | ||
let numEntriesCanceled = 0; | ||
// Canceling delayed entries | ||
for (const entry of this.delayedEntries.toArray()) { | ||
entry.cancel(); | ||
numEntriesCanceled += 1; | ||
} | ||
// Canceling scheduled entries | ||
for (const entry of this.heap.toArray()) { | ||
@@ -48,5 +58,8 @@ if (entry.cancel()) { | ||
}; | ||
/** Gets the total queue length, which may include canceled entries that haven't been purged yet */ | ||
this.getQueueLength = () => this.heap.size(); | ||
/** | ||
* Gets the total queue length, which may include canceled entries that haven't been purged yet and delayed entries that aren't yet | ||
* ready for execution | ||
*/ | ||
this.getQueueLength = () => this.heap.size() + this.delayedEntries.getLength(); | ||
/** | ||
* Schedules a new entry to be run. | ||
@@ -118,3 +131,8 @@ * | ||
let resolver; | ||
let delayedEntryNode = undefined; | ||
const timeout = setTimeout(() => __awaiter(this, void 0, void 0, function* () { | ||
if (delayedEntryNode !== undefined) { | ||
this.delayedEntries.remove(delayedEntryNode); | ||
delayedEntryNode = undefined; | ||
} | ||
runQueueEntry = this.scheduleImmediately(priority, id, run, options); | ||
@@ -139,3 +157,3 @@ try { | ||
}), options.delayMSec); | ||
return { | ||
const entry = { | ||
cancel: () => { | ||
@@ -152,2 +170,6 @@ if (wasResolved) { | ||
} | ||
if (delayedEntryNode !== undefined) { | ||
this.delayedEntries.remove(delayedEntryNode); | ||
delayedEntryNode = undefined; | ||
} | ||
resolver({ ok: false, details: consts_1.CANCELED }); | ||
@@ -162,2 +184,4 @@ }, | ||
}; | ||
delayedEntryNode = this.delayedEntries.append(entry); | ||
return entry; | ||
}; | ||
@@ -164,0 +188,0 @@ this.scheduleImmediately = (priority, id, run, options) => { |
{ | ||
"name": "client-run-queue", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "A client-friendly run queue", | ||
@@ -5,0 +5,0 @@ "keywords": ["promise", "concurrency", "limit", "throttle", "queue", "priority", "typescript", "client"], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59420
60
782