@programic/queue
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

@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

Package Sidebar

Install

npm i @programic/queue

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

9.14 kB

Total Files

6

Last publish

Collaborators

  • rbongers
  • thimonwentink
  • remcowolvenne