@alkolo/delay-queue

1.0.3 • Public • Published

@alkolo/delay-queue

npm (scoped)

npm bundle size (minified)

Executes tasks with fixed delay between them.

Install

$ npm install @alkolo/delay-queue

Dependencies

None.

Usage

const DelayQueue = require("@alkolo/delay-queue");
const queue = new DelayQueue(delay);
queue.addToQueue(task, doFirst);

where

  • delay: delay between tasks executions,
  • task: reference to a function to be executed,
  • doFirst: optional boolean value that tells that the task should be executed before other tasks that are already in the queue

Example

const DelayQueue = require("@alkolo/delay-queue");

const printQueue = new DelayQueue(1000); // set 1000 ms delay

printQueue.addToQueue(() => console.log("Item #1"));
printQueue.addToQueue(() => console.log("Item #2"));
printQueue.addToQueue(() => console.log("Item #3"), true); // put this task at the beginning of the queue
printQueue.addToQueue(() => console.log("Item #4"));
printQueue.addToQueue(() => console.log("Item #5"));

//=> Item #3
//   1 sec delay
//   Item #1
//   1 sec delay
//   Item #2
//   1 sec delay
//   Item #4
//   1 sec delay
//   Item #5

Readme

Keywords

Package Sidebar

Install

npm i @alkolo/delay-queue

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

3.85 kB

Total Files

4

Last publish

Collaborators

  • alkolo