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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pipe-queue

v0.0.6

Published

Put different pipe lines into a queue, stream pipe lines in this queue will run one by one. Use like a Promise with `when` and `then`.

Downloads

9

Readme

Pipe Queue

Put different pipe lines into a queue, stream pipe lines in this queue will run one by one. Use like a Promise with when and then.

Install

$ npm install pipe-queue

Usage

import

import PipeQueue from 'pipe-queque';

or

var PipeQueue = require('pipe-queue');

instantiate

var $queue = new PipeQueue();

when: begin the queue with one or more streams

$queue.when(stream1[,stream2,...])...

or you can use a callback function:

$queue.when((next,concat) => {
	var stream = ...
	stream.on('end',next);
})...

Callback function detail will be told later.

then: arrange your queue

$queue.when(...).then((next,concat) => {
	var stream = ...
	stream.on('end',next);
}).then(...)...

The callback function is as same as .when(). I will talk about it later.

end: do something in the end

$queue
.when(...)
.then((next,concat) => {
	var stream = ...
	stream.on('end',next);
})
.then(...)
...
.end(() => {
	// do something at the end
})

Notice: don't do something async in end callback function.

Only one end can be called, if you pend more than one, the last one will be use, and others will be dropped.

APIs

.when()

After instantiating, you will get an instance of PipeQueue, it has .when() to begin the queue.

  1. with streams:
$queue.when(stream1[,stream2,...])

You must pass stream data type into when so that .on('end',callback) can work successfully.

  1. with a callback function:
new PipeQueue().when(function(next,concat){
	var stream1 = ...,stream2 = ...
	concat(stream1,stream2,...).on('end',next)
})

I will talk about the detail of callback function later.

Notice: you must call next function in when callback function, or it will not run functions passed to then. And in then callback function, it is the same, you must call next before you end your queue.

.then()

After the beginning when, you have more tasks to do, put these tasks in then callback function. Functions passed to then() will be run one by one (called by next).

.then(function(next,concat){
	...// must call next()
}).then(...)...

.end()

You may want to do something after all then ended. You can pass a function into .end() to PipeQueue.

new PipeQueue().when(...).then(...).then(...).end(function(){
	// do something...
});

Notice: you must use next() in the last then() callback function to call end.

No parameters for end callback function.

callback function

You can use callback function in both when() and then(), but you must follow rules:

  • next() must be called before you end your queue, util .end().
  • all pipe streams are async, so be careful when you run more than one stream in a callback function, concat function recommended.

Callback function structure:

function(next,concat) {
	stream.on('end',next)
}

Sometimes, you may do something without streams, so you can call next() directly:

function(next,concat) {
	// do something
	next();
}

next()

To call the next then() callback function. Without a next call in callback function, queue will be paused in this place until you call next again.

In fact, next in callback function is an alias of PipeQueue.next(), so you can use the instance of PipeQueue to call next():

var $queue = new PipeQueue().then(...).then(...); // without next in then()
$queue.next();
// ...
$queue.next();
// ...

This give your freedom to do what you want.

concat()

This is a helper to contact serveral streams, so that you can do something after all of these streams ended:

function(next,concat) {
	var concatedStream = concat(stream1,stream2,...);
	concatedStream.on('end',next);
}

Notice: all streams are async.

You can also pass in an array (only one parameter):

function(next,concat) {
	var concatedStream = concat([stream1,stream2,...]);
	concatedStream.on('end',next);
}

However, you can know more about concat from here.

.promise()

The instance of PipeQueue has a .promise() property. This is for gulp, in a gulp task, only stream, promise and callback can notice the end of task. So when you want to notice gulp task end, use .promise() like this:

var PipeQueue = require('pipe-queue');
gulp.task('default',() => {
	var $queue = new PipeQueue();
	$queue.when(...).then(...)...
	return $queue.promise();
});

Notice: whenever you use pipe-queue, you should call next in then() callback function. If you don't do this, promise will not be resolved, and your task will never be end.

.stream()

Not only .promise() but also .steam() are provided to be more smart in gulp.

If you want pipe-queue to return a stream, just like .pipe do, you can return a .stream() to convert the result to be a stream.

var PipeQueue = require('pipe-queue');
gulp.task('default',() => {
	var $queue = new PipeQueue();
	$queue.when(...).then(...)...
	return $queue.stream();
});

Notice: whenever you use pipe-queue, you should call next in then() callback function. If you don't do this, stream will not emit a end event, and your task will never be end.

Development

This package is written by ES6, use componer to build source code.