New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

conqueue

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conqueue

Multifunctional asynchronous concurrent queue

  • 2.0.1
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Conqueue

ci Status snyk npm downloads/month npm downloads license

Description

Conqueue is a simple yet powerful asynchronous queue implementation for managing concurrency and controlling the flow of asynchronous tasks. It supports various modes, such as callbacks, promises, FIFO, LIFO, priority, factor and round-robin, providing flexibility for different use cases.

Features

  • Concurrency Control: Limit the number of concurrent tasks to prevent resource overload.
  • Task Priority: Assign priorities to tasks for customized task execution order.
  • Task Timeout: Set a timeout for individual tasks to handle situations where a task takes too long to complete.
  • Debouncing: Control task execution frequency with debouncing, useful for scenarios with rapid task submissions.
  • Promise Mode: Execute tasks that return promises, providing seamless integration with promise-based workflows.
  • Event Handling: Attach event listeners to handle various events, such as task success, failure, done, timeout and queue drain.

Installation

npm install conqueue

Usage

const Queue = require('conqueue');

const job = (taskId, cb) => {
  setTimeout(() => {
    if (taskId === 4) {
      cb(new Error('Biggest error!!!'));
      return;
    }
    cb(null, taskId);
  }, 0);
};

// Create a queue with a concurrency limit of 3
const queue = new Queue(3)
  .process(job)
  .done((err, res) => {
    if (err) console.error(err);
    else console.log(res);
  })
  .success(({ res }) => {
    console.log(`Response: ${res}`);
  })
  .failure((err) => {
    console.error(`Task failed: ${err}`);
  })
  .drain(() => {
    console.log('Queue drain!');
  });

// Add tasks to the queue
for (let i = 0; i < 10; i++) {
  queue.add(i);
}

API Reference

Queue(concurrency, size = Infinity)

  • Constructor:
    • concurrency: Maximum number of tasks to be executed concurrently.
    • size: Maximum size of the queue (default is Infinity).
  • Methods:
    • add(item: any, options?: AddOptions): Add a task to the queue with optional factor and priority.
    • pipe(destination: Queue): Pipe the queue output to another queue.
    • timeout(msec: number, onTimeout: function): Set the maximum execution time for each task.
    • wait(msec: number): Set a waiting time before processing tasks.
    • debounce(count: number, interval: number): Control the execution frequency using debouncing.
    • resume(): Resume the execution of the paused queue.
    • pause(): Pause the queue to stop processing new tasks.
    • clear(): Clear the queue and reset counters.
    • process(listener: function): Set a listener function to process each task.
    • done(listener: function): Set a listener function called after each task is processed.
    • success(listener: function): Set a listener function for successful task execution.
    • failure(listener: function): Set a listener function for failed task execution.
    • drain(listener: function): Set a listener function called when the queue is drained.
    • fifo(): Set the queue mode to First-In-First-Out (default).
    • lifo(): Set the queue mode to Last-In-First-Out.
    • priority(flag: boolean): Enable or disable priority mode.
    • setFactor(factor: boolean): Set a factor for tasks in round-robin mode.
    • roundRobin(flag: boolean): Enable or disable round-robin mode.
    • promise(): Enable promise mode to execute tasks returning promises.
    • callback(): Switch back to callback mode.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Keywords

FAQs

Package last updated on 06 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc