1.0.4 • Published 4 years ago
@programic/queue v1.0.4
@programic/queue
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 --saveyarn add @programic/queueUsage
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 firedrunningTasks(property: Task[]) contains the tasks that are currently runningfailedTasks(property: FailedTask[]) contains the failed tasks with meta info like the errorisRunning(method: boolean) indicates if the queue is runningpush(method: void) method to push a new task to the queue