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

limiting-queue

v1.2.1

Published

A queue which will callback to a user defined function on each item of the queue, limiting parallel tasks using promises and deferreds.

Downloads

28

Readme

BuildStatus

Code Climate

Test Coverage

A Limitedly parallel queue for NodeJS

Usage

var LimitingQueue = require('limiting-queue');

var queue = new LimitingQueue(options);

Options

All of these options can be modified after intitalization by setting them ine the queue.opts object.

So, for instance:

queue.opts.maxWorkers = 3;

or, to reset an option back to its default:

delete opts.maxWorkers;

maxWorkers

The maximum numbers of simultaneous workers. An integer greater than zero. Any negative number will be interpreted as "no limit." Defaults to -1.

maxRetries

The maximum number of retries for a queue entry. An integer greater than zero. Any negative number will be interpreted as "no limit." Defaults to -1.

maxWait

The number of milliseconds to wait before declaring a job failed by timeout. An integer greater than zero. Any negative number will be interpreted as "no limit." Defaults to -1.

maxQueueSize

The maximum allowed number of items waiting in the queue. Integer greater than zero. Any negative number will be interpreted as no limit. Defaults to -1.

callback

The function to call to do work on a queue entry. May optionally return a function to be called in case of a timeout (to do any necessary cleanup). Defaults to a function which trivially declares the object complete.

Takes three parameters:

payload

The information previously passed into the "push" function.

previousAttempts

The number of times this payload has previously been pushed to this function.

deferred

The deferred object to declare success or failure on the queue item. Call deferred.fulfill() to declare success, and deferred.reject(error) to declare a failure.

failure

The function to call when a queue entry flunks out of the queue entirely.
Defaults to an empty function.

Takes three parameters:

payload

The information previously passed into the "push" function.

totalAttempts

The total number of attempts made to process this information.

errors

The array of errors that caused this to error out - in order.

progress

A progress callback to be called every time a new worker starts.

Takes two paramters:

queueSize

The number of jobs in the queue. (Not being worked on.)

workers

The number of workers currently working.

autoStart

Pass true to start the queue immediately, false to let it wait.

retryImmediately

Pass true to push failed jobs to the head of the queue, false to push them to the back.

Methods

queue.push(payload)

Push a new job to the front of the queue. Returns true if the job is added, false otherwise.

queue.append(payload)

Append to the back of the queue. Returns true if the job is added, false otherwise.

queue.prioritize(payload, priority)

Adds an item into the queue after all the items with higher or equal priority, but before any items with lower priority. Default priority is 0. Returns true if the job is added, false otherwise.

It is NOT recommended to mix and match prioritize and push/append, as the first is a relative insertion method, and the latter are absolute. This can lead to unexpected behaviour.

queue.size()

Returns the number of objects waiting in the queue.

queue.workers()

Returns the number of active workers.

queue.start()

Start the queue.

queue.stop()

Stop the queue. This does not cancel working workers - it just ceases the creation of new workers.

queue.forEach()

Execute a function on each member currently in the queue without removing it from the queue. This function is sequential in nature.

Contributing

Please maintain the existing style - but do open a pull request if you have a bugfix or a cool feature. Be sure to document your change. Pull requests are preferred to bug reports (though if you submit a bug report, you're welcome to fix your own bug).

Please be sure to update all documentation to reflect your changes - add to the Readme files and the in code commenting.