Comparing version 1.3.0 to 1.3.1
@@ -15,2 +15,3 @@ type ActualTask<Task> = Task extends object ? Readonly<Task> : Task; | ||
onDrain: () => void; | ||
mergeConsecutiveOnly: boolean; | ||
taskDelay: number; | ||
@@ -17,0 +18,0 @@ retryOnFailure: boolean; |
@@ -25,2 +25,3 @@ "use strict"; | ||
onDrain: options.onDrain ?? (() => { }), | ||
mergeConsecutiveOnly: Boolean(options.mergeConsecutiveOnly), | ||
taskDelay: options.taskDelay ?? 0, | ||
@@ -45,4 +46,5 @@ retryOnFailure: Boolean(options.retryOnFailure), | ||
const incomingItem = { task: incomingTask, key, delayPromise: null, retried: false, resolve, reject }; | ||
const existingKeyItemIndex = this._queue.findIndex((item) => item.key === key); | ||
const existingKeyItem = existingKeyItemIndex > -1 ? this._queue[existingKeyItemIndex] : null; | ||
const existingKeyItemIndex = this._queue.findLastIndex((item) => item.key === key); | ||
const allowedMerge = !this._options.mergeConsecutiveOnly || existingKeyItemIndex === this._queue.length - 1; | ||
const existingKeyItem = existingKeyItemIndex > -1 && allowedMerge ? this._queue[existingKeyItemIndex] : null; | ||
if (existingKeyItemIndex > -1 && existingKeyItem) { | ||
@@ -128,3 +130,4 @@ const mergedItem = this._mergeQueueItems(existingKeyItem, incomingItem); | ||
const queuedKeyItemIndex = this._queue.findIndex((queuedItem) => queuedItem.key === currentItem.key); | ||
const queuedKeyItem = queuedKeyItemIndex > -1 ? this._queue[queuedKeyItemIndex] : null; | ||
const allowedMerge = !this._options.mergeConsecutiveOnly || queuedKeyItemIndex === 0; | ||
const queuedKeyItem = queuedKeyItemIndex > -1 && allowedMerge ? this._queue[queuedKeyItemIndex] : null; | ||
if (queuedKeyItemIndex > -1 && queuedKeyItem) { | ||
@@ -141,3 +144,4 @@ const mergedItem = this._mergeQueueItems(retriedItem, queuedKeyItem); | ||
const queuedKeyItemIndex = this._queue.findLastIndex((queuedItem) => queuedItem.key === currentItem.key); | ||
const queuedKeyItem = queuedKeyItemIndex > -1 ? this._queue[queuedKeyItemIndex] : null; | ||
const allowedMerge = !this._options.mergeConsecutiveOnly || queuedKeyItemIndex === this._queue.length - 1; | ||
const queuedKeyItem = queuedKeyItemIndex > -1 && allowedMerge ? this._queue[queuedKeyItemIndex] : null; | ||
if (queuedKeyItemIndex > -1 && queuedKeyItem) { | ||
@@ -144,0 +148,0 @@ const mergedItem = this._mergeQueueItems(queuedKeyItem, retriedItem); |
{ | ||
"name": "suprqueue", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Simple in-memory promise-based task queue with support for pausing, merging tasks, or retrying failed tasks", | ||
@@ -5,0 +5,0 @@ "main": "dist/Suprqueue.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
184156
3975