Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

queue

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queue

asynchronous function queue with adjustable concurrency

  • 7.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7M
decreased by-28.38%
Maintainers
1
Weekly downloads
 
Created

What is queue?

The 'queue' npm package is a fast, robust, and extensible queue implementation for managing a list of tasks in a sequential manner. It allows for asynchronous task processing, concurrency control, timeout for tasks, and pausing/resuming the queue. This package is particularly useful for rate-limiting tasks or operations that need to be executed in order but might have asynchronous results, such as API calls, file processing, or any task that requires throttling.

What are queue's main functionalities?

Basic Queue Functionality

This demonstrates how to create a basic queue, add tasks to it, and start processing. Each task is a function that accepts a callback, which must be called upon completion.

const queue = require('queue');
const q = queue();
q.push(function(cb) {
  console.log('Hello');
cb();
});
q.push(function(cb) {
  console.log('World');
cb();
});
q.start(function(err) {
  console.log('All tasks finished.');
});

Concurrency Control

This example shows how to set a concurrency limit, allowing up to 2 tasks to be processed simultaneously.

const q = queue({concurrency: 2});
// Add tasks to q
q.start(function(err) {
  console.log('All tasks processed with a maximum of 2 tasks concurrently.');
});

Timeout for Tasks

This code sets a timeout for each task in the queue. If a task does not call its callback within the specified timeout, the queue will move on to the next task.

const q = queue();
q.timeout = 1000; // 1 second timeout for each task
q.push(function(cb) {
  setTimeout(function() {
    console.log('This task will timeout');
    cb();
  }, 1500); // This task takes longer than the timeout
});
q.start();

Other packages similar to queue

Keywords

FAQs

Package last updated on 11 Apr 2023

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