Comparing version 1.0.1 to 1.0.2
@@ -0,1 +1,2 @@ | ||
type ActualTask<Task> = Task extends object ? Readonly<Task> : Task; | ||
interface QueueItem<Task, TaskResult> { | ||
@@ -19,11 +20,11 @@ task: Task; | ||
export declare class Suprqueue<Task, TaskResult> { | ||
_processTask: (task: Task) => Promise<TaskResult> | TaskResult; | ||
_options: QueueOptions<Task>; | ||
_queue: Array<QueueItem<Task, TaskResult>>; | ||
_processTask: (task: ActualTask<Task>) => Promise<TaskResult> | TaskResult; | ||
_options: QueueOptions<ActualTask<Task>>; | ||
_queue: Array<QueueItem<ActualTask<Task>, TaskResult>>; | ||
_running: boolean; | ||
_paused: boolean; | ||
constructor(processTask: (task: Task) => Promise<TaskResult> | TaskResult, options?: Partial<QueueOptions<Task>>); | ||
constructor(processTask: (task: ActualTask<Task>) => Promise<TaskResult> | TaskResult, options?: Partial<QueueOptions<ActualTask<Task>>>); | ||
pause(): void; | ||
resume(): void; | ||
pushTask(incomingTask: Task): Promise<TaskResult>; | ||
pushTask(incomingTask: ActualTask<Task>): Promise<TaskResult>; | ||
private _processQueue; | ||
@@ -30,0 +31,0 @@ private _processNextTask; |
@@ -7,2 +7,6 @@ "use strict"; | ||
class Suprqueue { | ||
// NOTE: Only non-primitive task types can be made readonly. | ||
// For example `Readonly<string>` results in `Readonly<{ toString: …, …}>` and TS will not even allow | ||
// the processTask function to be used to infer the string task type from `(task: string) => {}`, | ||
// requiring the `Readonly<string>` type instead. | ||
_processTask; | ||
@@ -13,3 +17,9 @@ _options; | ||
_paused = false; | ||
constructor(processTask, options = {}) { | ||
constructor( | ||
// WARN: TS cannot constrain the task type to be readonly unless it is specified as a type parameter of the class | ||
// such as `new Suprqueue<MyTask, MyResult>((task) => {})`. Inferring the type from the `processTask` function | ||
// as `new Suprqueue((task: MyTask) => {})` will allow mutation of the task object by the function | ||
// (although other functions in the `options` object will work fine). It is also possible to set the readonly | ||
// flag in the `processTask` function parameter as `(task: Readonly<MyTask>) => {}`. | ||
processTask, options = {}) { | ||
this._processTask = processTask; | ||
@@ -16,0 +26,0 @@ this._options = { |
{ | ||
"name": "suprqueue", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"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
182625
3963