2.1.4 • Published 8 years ago

simple-queuer v2.1.4

Weekly downloads
7
License
ISC
Repository
github
Last release
8 years ago

queuer

Introduction

This is a simple queueing mechanism. It uses interval to check remaining items in the queue. Uses es2015 syntaxes.

Installation

$ npm install --save simple-queuer;

Usage: basic

// import the class
import Queuer from 'simple-queuer';

// instantiate
var queuer = new Queuer(10); // the default value is 10.

// add tasks. this will automatically start the queue.
queuer.push(
	function(next){
		setTimeout(()=>{next()}, 1000);
	}
);

Usage: async with promise

"use strict";

// import the class
import Queuer from 'simple-queuer';

// instantiate
var queuer = new Queuer(10); // the default value is 10.

function getRandomTimer(){
	return new Promise( (resolve, reject) => {
		let timer = (next) => {
			setTimeout(()=>{
				console.log('timer '+i+' done!')
				resolve(i);
			}, Math.random()*1000);
		}
		queuer.push(timer);
	});
}

// let's create 100 random timers
var promises = [];
for(var i=0; i< 100; i++){
	promises.push(getRandomTimer());
}
Promise
	.all(promises)
	.then((results) => {
		console.log('all timers done!');
	})
;
2.1.4

8 years ago

2.1.3

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.11

8 years ago

2.0.10

8 years ago

2.0.9

8 years ago

2.0.8

8 years ago

2.0.7

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.0

8 years ago