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

better-queue

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-queue

Better Queue for NodeJS

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
117K
increased by0.16%
Maintainers
1
Weekly downloads
 
Created

What is better-queue?

better-queue is a simple and efficient job queue for Node.js. It allows you to manage and process tasks asynchronously, with features like priority handling, concurrency control, and job persistence.

What are better-queue's main functionalities?

Basic Queue

This code demonstrates how to create a basic queue and add tasks to it. The tasks are processed asynchronously.

const Queue = require('better-queue');

let q = new Queue(function (input, cb) {
  console.log('Processing:', input);
  cb(null, input);
});

q.push('Task 1');
q.push('Task 2');

Concurrency Control

This code shows how to set up a queue with concurrency control, allowing up to 2 tasks to be processed simultaneously.

const Queue = require('better-queue');

let q = new Queue(function (input, cb) {
  console.log('Processing:', input);
  setTimeout(() => cb(null, input), 1000);
}, { concurrent: 2 });

q.push('Task 1');
q.push('Task 2');
q.push('Task 3');

Priority Handling

This code demonstrates how to add tasks with different priorities to the queue. Higher priority tasks are processed first.

const Queue = require('better-queue');

let q = new Queue(function (input, cb) {
  console.log('Processing:', input);
  cb(null, input);
});

q.push('Low Priority Task', { priority: 10 });
q.push('High Priority Task', { priority: 1 });

Job Persistence

This code shows how to set up job persistence using an in-memory store. This allows tasks to be stored and retrieved even if the process is restarted.

const Queue = require('better-queue');
const Store = require('better-queue-memory');

let q = new Queue(function (input, cb) {
  console.log('Processing:', input);
  cb(null, input);
}, { store: new Store() });

q.push('Persistent Task');

Other packages similar to better-queue

Keywords

FAQs

Package last updated on 08 Mar 2016

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