Socket
Book a DemoInstallSign in
Socket

grouped-queue

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grouped-queue

In memory queue system prioritizing tasks

2.1.0
latest
Source
npmnpm
Version published
Weekly downloads
862K
7.6%
Maintainers
2
Weekly downloads
 
Created
Source

Grouped Queue

In memory queue system prioritizing tasks.

Documentation

Installation

npm install --save grouped-queue

Methods

Constructor

The constructor takes an optional array of task groups. The first String name will be the first queue to be emptied, the second string will be the second group emptied, etc.

By default, the constructor will always add a default queue in the last position. You can overwrite the position of the default group if you specify it explicitly.

import Queue from "grouped-queue";

const queue = new Queue(["first", "second", "third"]);

Queue#add add( [group], task, [options] )

Add a task into a group queue. If no group name is specified, default will be used.

Implicitly, each time you add a task, the queue will start emptying (if not already running).

Each task function is passed a callback function. This callback must be called when the task is complete.

queue.add((cb) => {
  DB.fetch().then(cb);
});

Option: once

You can register tasks in queues that will be dropped if they're already planned. This is done with the once option. You pass a String (basically a name) to the once option.

// This one will eventually run
queue.add(method, { once: "readDB" });

// This one will be dropped as `method` is currently in the queue
queue.add(method3, { once: "readDB" });

Option: run

You can register a task without launching the run loop by passing the argument run: false.

queue.add(method, { run: false });

Delaying runs

If you don't want tasks to run as they're added, you can hold the queue until manually starting.

const queue = new Queue(
  ["first", "second", "third"],
  // `runOnAdd` option; this boolean instruct the queue to not auto-start.
  false,
);

// Later on, to start processing
queue.start();

// And pause to stop processing new tasks; running task will complete.
queue.pause();

Events

end

This event is called each time the queue emptied itself.

queue.on("end", () => {
  console.log("done!");
});

Contributing

  • Unit test: Unit tests are written in Mocha. Please add a unit test for every new feature or bug fix. npm test to run the test suite.
  • Documentation: Add documentation for every API change. Feel free to send corrections or better docs!
  • Pull Requests: Send fixes PR on the master branch.

License

Copyright (c) 2013 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.

Keywords

queue

FAQs

Package last updated on 17 Aug 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.