simple-js-task-queue
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

simple-js-task-queue

A simple javascript/typesciprt tasks queue that supports concurrency control, designed by Shuo Feng

Table of Contents

Introduction

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.

Features

  • 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.

Installation

npm install simple-js-task-queue

Or

yarn add simple-js-task-queue

Demo

Check out this codesanbox project!

Usage

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.');
  });

API Reference

TaskQueue Class

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. taskId

For more detailed information on each method, including parameter types and return values, please refer to the TypeDoc generated documentation in the docs folder or this link.

License

This library is MIT licensed.

Package Sidebar

Install

npm i simple-js-task-queue

Weekly Downloads

16

Version

0.2.2

License

MIT

Unpacked Size

138 kB

Total Files

44

Last publish

Collaborators

  • supfriday