⚠️ Deprecation Notice: This package has been renamed totaskon
. Thesimple-js-task-queue
package is now in legacy mode and will no longer receive regular updates or feature improvements. Only critical bug fixes will be applied to this package if any major bugs are found.
To migrate to taskon
, follow these simple steps:
- Install the new package:
yarn add taskon
# or
npm install taskon
- Update your imports:
- import { TaskQueue } from 'simple-js-task-queue';
+ import { TaskQueue } from 'taskon';
That's it! No other code changes are needed as taskon
maintains full API compatibility.
This lightweight, error-tolerant, no-dependency library provides a sophisticated taks queue management system designed for TypeScript and JavaScript applications, providing advanced functionalities for managing, executing, and monitoring synchronous and asynchronous tasks.
- Advanced Task Management: Efficiently manage tasks with customizable priorities and statuses.
- Concurrency Control: Fine-tune the execution of tasks with dynamic concurrency settings.
- Error Handling: Comprehensive options for error management including retry mechanisms.
- Integrated Logging: Leverage built-in logging for easy monitoring and debugging.
- Flexible Task Prioritization: Utilize various prioritization strategies to control task execution order.
yarn add simple-js-task-queue
Or
npm install simple-js-task-queue
Check out this codesanbox project!
Below is a simple example demonstrating how to use the TaskQueue
to add and execute a task:
import { TaskQueue } from 'simple-js-task-queue';
const queue = new TaskQueue();
queue
.addTask(async () => {
console.log('Performing a task...');
// Task implementation
})
.then((result) => {
console.log('Task completed.');
});
The TaskQueue
class is at the core of the library, offering a rich set of methods to manage tasks:
Method Name | Description | Parameters |
---|---|---|
addTask |
Adds a new task to the queue. | callback, onStatusUpdate?, priority? |
addPrioritizedTask |
Adds a high-priority task to the queue. | callback, onStatusUpdate? |
addTasks |
Bulk addition of tasks. | tasks |
adjustConcurrency |
Adjusts the number of tasks that can run concurrently, effective instantly. | newConcurrency |
start |
Starts or resumes task execution. | |
stop |
Pauses task execution. | |
retry |
Retries failed tasks. | |
subscribeTaskStatusChange |
Subscribes to task status updates. | onTaskStatusUpdate |
unsubscribeTaskStatusChange |
Unsubscribes from task status updates. | onTaskStatusUpdate |
getTaskDetails |
Fetches details of a specific task. | taskId |
getAllTasksDetails |
Retrieves details of all tasks, optionally filtered by status. | status? |
getConcurrency |
Fetches the concurrency of the task queue. | |
isManuallyStopped |
Checks if the task queue is manually stopped. | |
clearTaskDetails |
Clears details of a specific task. | taskId |
clearAllTasksDetails |
Removes details of all tasks from memory. | |
clearFailedRetryableTasks |
Clears the list of failed tasks marked for retry. | |
clearWaitedTasks |
Removes all tasks waiting to be executed. | |
removeFailedRetryableTask |
Removes a specific task from the retry list. | taskIdOrTask |
removeWaitedTask |
Removes a specific task from the waiting list. | taskIdOrTask |
This library is MIT licensed.