0.0.4 • Published 7 years ago

rps-queue v0.0.4

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

rps-queue NPM version

A queue that will dequeue (call a provided function) at a given rate and has a max number concurrent (active functions running)

Installation

$ npm install --save rps-queue

Usage

For a full API reference, see API.md.

'use strict';
const Promise = require('bluebird');
const RpsQueue = require('rps-queue');
let rpsQueue = new RpsQueue({
	requestsPerSecond: 2,
	maxConcurrent: 2
});

function logMetrics() {
	console.log('NumProcessed:', rpsQueue.getNumProcessed());
	console.log('QueueLength:', rpsQueue.getQueueLength());
	console.log('NumConcurrent:', rpsQueue.getNumConcurrent());
	console.log('--------------');
}

rpsQueue.add(() => {
	return Promise.delay(3000).then(() => {
		console.log('Done number 1');
	});
}).then(() => logMetrics());
rpsQueue.add(() => {
	return Promise.delay(3000).then(() => {
		console.log('Done number 2');
	});
}).then(() => logMetrics());
rpsQueue.add(() => {
	return Promise.delay(3000).then(() => {
		console.log('Done number 3');
	});
}).then(() => logMetrics());
rpsQueue.add(() => {
	return Promise.delay(3000).then(() => {
		console.log('Done number 4');
	});
}).then(() => {
	logMetrics();
	rpsQueue.stop();
});

License

ISC © Derek MacDonald

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago