0.1.5 • Published 6 years ago

pstack v0.1.5

Weekly downloads
109
License
-
Repository
github
Last release
6 years ago

pStack: Sync & Async stacking and queuing

pStack is an incredibly useful way to create sync and async queues, and get your callback executed once the queue has been processed.

Install

npm install pstack

Usage

var pstack = require('pstack');

var stack = new pstack();

stack.add(function(done) {
	// do something...
	// then execute the callback when the task is done
	done();
});

stack.add(function(done) {
	// do something else...
	// then execute the callback when the task is done
	done();
});

// Start the queue
stack.start(function() {
	console.log("The queue has finished processing");
});

Options

// Async: All the items in the queue will execute in parallel
var stack = new pstack({
	async:	true // default to false
});

// Show a progress bar in the console
var stack = new pstack({
	progress: 'Processing the queue... '
});
// In the console, you'll see a progress bar:
// Processing the queue...  [==============    ] 80% [8/10] 0.6s

Example

var pstack = require('pstack');

var stack = new pstack({
	progress: 'Processing the queue... '
});

// Add 100 taks, and each will simulate a completing in 200ms
for (var i=0;i<100;i++) {
	stack.add(function(done) {
		setTimeout(function() {
			done();
		}, 200);
	});
}

// Start the queue
stack.start(function() {
	console.log("The queue has finished processing");
});