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

seq-queue

v0.0.5

Published

A simple tool to keep requests to be executed in order.

Downloads

10,657,234

Readme

#seq-queue Seq-queue is simple tool to keep requests to be executed in order.

As we known, Node.js codes run in asynchronous mode and the callbacks are unordered. But sometimes we may need the requests to be processed in order. For example, in a game, a player would do some operations such as turn right and go ahead. And in the server side, we would like to process these requests one by one, not do them all at the same time.

Seq-queue takes the responsibility to make the asynchronous, unordered processing flow into serial and ordered. It's simple but not a repeated wheel.

Seq-queue is a FIFO task queue and we can push tasks as we wish, anytime(before the queue closed), anywhere(if we hold the queue instance). A task is known as a function and we can do anything in the function and just need to call task.done() to tell the queue current task has finished. It promises that a task in queue would not be executed util all tasks before it finished.

Seq-queue add timeout for each task execution. If a task throws an uncaught exception in its call back or a developer forgets to call task.done() callback, queue would be blocked and would not execute the left tasks. To avoid these situations, seq-queue set a timeout for each task. If a task timeout, queue would drop the task and notify develop by a 'timeout' event and then invoke the next task. Any task.done() invoked in a timeout task would be ignored.

##Installation

npm install seq-queue

##Usage

var seqqueue = require('seq-queue');

var queue = seqqueue.createQueue(1000);

queue.push(function(task) {
	setTimeout(function() {
		console.log('hello ');
		task.done();
	}, 1000);
});

queue.push(function(task) {
	setTimeout(function() {
		console.log('world~');
		task.done();
	}, 500);
});

##API ###seqqueue.createQueue(timeout) Create a new queue instance. A gloabal timeout value in ms for the new instance can be set by timeout parameter or use the default timeout (3ms) by no parameter.

###queue.push(fn, timeout) Add a task into the queue instance. ####Arguments

  • fn(task) - The function that describes the content of task and would be invoke by queue. fn takes a arguemnt task and we must call task.done() to tell queue current task has finished.
  • timeout - Timeout in ms for fn. If specified, it would overwrite the gloabal timeout that set by createQueue for fn.

###queue.close(force) Close the queue. A closed queue would stop receiving new task immediately. And the left tasks would be treated in different ways decided by force. ####Arguments

  • force - If true, queue would stop working immediately and ignore any tasks left in queue. Otherwise queue would execute the tasks in queue and then stop.

##Event Seq-queue instances extend the EventEmitter and would emit events in their life cycles. ###'timeout'(totask) If current task not invoke task.done() within the timeout ms, a timeout event would be emit. totask.fn and totask.timeout is the fn and timeout arguments that passed by queue.push(2). ###'closed' Emit when the close(false) is invoked. ###'drained' Emit when close(true) is invoked or all tasks left have finished in closed status.