npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multiqueue

v0.4.2

Published

A simple Node.JS function queuing module with multiple queues

Downloads

3

Readme

Multiqueue

A simple Node.JS function queuing module with multiple queues

NPM version Dependencies Github issues

What it does

This module allows you to have multiple queues with functions that will be processed one at a time at a set interval. Each queue operates independently from the others.

Basic Usage

Install the module through npm

npm install multiqueue --save

Require the module in your code

var multiq = require('multiqueue');

Add a function to the queue

multiq.add(function(callback){
	var a = 1 + 1; // Or you could, you know, do something useful instead
	callback(false, a);
}, function(err, data){
	console.log(data); // 2
});

If there are no other functions in the queue, this function will run right away. Otherwise it will be added to the end of the queue, and it will be executed as soon as the previous functions have been processed.

That's it, basically.

Queues

Out of the box Multiqueue uses the default queue, which has the default interval of 1 second.

You can add a custom queue easily by using the create method.

multiq.create('myQueue');

This will create a new queue called myQueue. You can then use this queue by adding the queue ID as an additional parameter to the multiqueue functions.

multiq.add(function(callback){
	var a = 1 + 1; // Or you could, you know, do something useful instead
	callback(false, a);
}, function(err, data){
	console.log(data); // 2
}, 'myQueue');

Error handling & retrying

If something goes wrong, Multiqueue can try to run your function again. This may be useful if you are doing stuff that can fail sometimes, but succeed others (e.g. HTTP requests). The default queue does not retry, but when you create a custom queue you can set the retry limit to pretty much whatever you want.

Note: Retries are removed from their position in the queue and re-added to the end of the queue.

When a function in the queue fails, the error message is passed along to the callback function. The err argument in the callback function will be an array containing the error messages from each try.

API

Create

multiqueue.create(queueID [, interval][, limit]);

This will create a new queue with the specified queueID.

Argument | Type | Description ---------|--------|------------- queueID | String | ID of the queue interval | Number | Interval in milliseconds between each function in the queue (default: 1000) limit | Number | How many times to retry a failing function before returning an error (default: 1)

Add

multiqueue.add(function, callback [, queueID]);

This will add a function to the specified queue.

Argument | Type | Description ---------|----------|------------- function | Function | Function to run. It takes one argument, callback, which should be called when the function has completed. callback | Function | This will be called when the function has completed. It has the standard Node arguments err and data. queueID | String | ID of the queue (default: 'default')

Queue Properties

Set Interval

multiqueue.setInterval(interval [, queueID]);

This sets the interval of the specified queue

Argument | Type | Description ---------|--------|------------- interval | Number | Interval in milliseconds between each function in the queue queueID | String | ID of the queue (default: 'default')

Set Limit

multiqueue.setInterval(limit [, queueID]);

This sets the retry limit of the specified queue

Argument | Type | Description ---------|--------|------------- limit | Number | How many times to retry a failing function before returning an error queueID | String | ID of the queue (default: 'default')

Default Values

Set Default Interval

multiqueue.setDefaultInterval(interval);

This sets the default interval for new queues

Argument | Type | Description ---------|--------|------------- interval | Number | Interval in milliseconds between each function in the queue

Set Default Limit

multiqueue.setDefaultLimit(limit);

This sets the default limit for new queues

Argument | Type | Description ---------|--------|------------- limit | Number | How many times to retry a failing function before returning an error

Queues

multiqueue.queues

This will return an object containing information about the queues.

console.log(multiq.queues); will output (with only the default queue):

{
	default: {
		interval: 1000,
		length: 0,
		limit: 1,
		add: [Function],
		setInterval: [Function],
		setLimit: [Function]
	}
}

The functions in each queue object are the same as the main multiqueue functions of the same name, except that you don't need the queueID argument.

Credits, copyright, etc

Created by me. Feel free to use this code, change it, do whatever you want with it, all I ask is that you let me know cause I'm interested in seeing my code being used by others. Pull requests are welcome, as are ideas for new features, and be sure to report any problems or bugs so that I can fix them.

This module is under development by me, and will be expanded as I see fit. I developed this because I needed this specific functionality so as the requirements grow and the project for which I need it expands, so will this module.