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

queuer.js

v0.5.0

Published

Run easily queue of tasks.

Downloads

38

Readme

Queuer

Run easily queue of tasks.

Installation

It is available with bower or npm:

bower install queuer.js
npm install queuer.js

Include queuer.min.js to the HTML, and the queuer object is now available in the global scope:

<script type="text/javascript" src="/path/to/bower_components/queuer.js/dist/queuer.min.js"></script>

Alternately, you can use a module manager to avoid global scoping:

var queuer = require('queuer.js');
// or es6 import
import queuer from 'queuer.js';

Usage

Create a queue

var queue = queuer();

Register tasks on it

queue.task('task1', function(payload, queue) {
    // the payload will be either the result of the previous task
    // or the initial payload given to the queue if it is the first task
     
    // the queue argument is the task's queue
    
    console.log('I am a task');

    // if you want to deal with async task you must return a promise.
});

Running the queue

queue(initialPayload) // You can pass an initial payload to the queue
    .then(function(payload) {
        // everything worked
        // the payload is the result returned by the last task
    })
    .catch(function(error) {
        // an error occured, the queue was stopped
    });

Dealing with events

The queue is an event emitter. That means you can emit or listen events on it. The queue already emit some events:

  • EVENT_TASK_START: A task was started.
  • EVENT_TASK_STOP: A task was stopped.
  • EVENT_TASK_START: A task threw an error.
  • EVENT_CANCEL: The queue was canceled.

To register an event listener use on(event, listener) or once(event, listener) method on the queue:

queue.on(queue.EVENT_TASK_START, function(taskName, payload) {
    // taskName was started with the given payload
    // other task events have the save listener signature
});

queue.once(queue.EVENT_CANCEL, function() {
    // the queue was cancelled
    // we use once instead of on because it will happen only once
});

As the queue is given as an argument to the task, you can use it in tasks to listen or to emit some custom event as you wish:

queue.task('task1', function(payload, queue) {
    queue.once(queue.EVENT_CANCEL, function() {
        // the queue was canceled, we use this to cancel our task's asynchronous operations
    });

    queue.on('myCustomEvent', function(data) {
        // we listen to our custom event
    });
});

queue.emit('myCustomEvent', 'test');

Cancel the queue

The queue exposes a shorcut method to cancel it queue.cancel(). You can pass arguments to it if you wish, they will be forwarded across the cancel event.

Development

Installation

make install

Build

make build or make build-dev (unminified version)

Watch

make watch

Test

make test

Contributing

All contributions are welcome and must pass the tests. If you add a new feature, please write tests for it.

License

This application is available under the MIT License.