programic / queue-js

A simple queue for JavaScript/TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@programic/queue

npm version

This is a simple JavaScript/TypeScript queue. It contains a push method to add a task (method) to the queue.

Simple example

import { createQueue } from '@programic/queue';

const queue = createQueue();

queue.push(() => 'First task');
queue.push(async () => 'Second task');

Installation

To use this package, install @programic/queue as a dependency in your project with npm or yarn:

npm install @programic/queue --save
yarn add @programic/queue

Usage

To create a new queue instance, use the createQueue method (like the example above). It has one parameter numberOfParallelTasks which is 1 by default. You can provide a higher value to run multiple tasks simultaneously.

Queue instance properties and methods

Every queue instance has the following methods and properties:

  • enqueuedTasks (property: array) contains the tasks that are waiting to be fired
  • runningTasks (property: Task[]) contains the tasks that are currently running
  • failedTasks (property: FailedTask[]) contains the failed tasks with meta info like the error
  • isRunning (method: boolean) indicates if the queue is running
  • push (method: void) method to push a new task to the queue

About

A simple queue for JavaScript/TypeScript

License:MIT License


Languages

Language:TypeScript 100.0%