eque

0.0.3 • Public • Published

Eque

Eque is a async queuing mechanism for fixed job sets. It shines with its ability to spawn/destroy workers in an async manner at the same time as queuing jobs.

Usage

EQue.start({
	createWorkerConcurrency: 2,
 
	totalWorkers: queueNames.length,
 
	jobs: [
		function (worker) {
			return new Promise(function (resolve, reject) {
				console.log(worker);
				resolve();
			});
		}
	],

	onCreateWorker: function () {
		// async code for creating the worker expects a resolve(worker), or resolve(null) if you want to skip the creation of the worker
		return new Promise(function (resolve, reject) {
			setTimeout(function () {
				var worker = queueNames.shift();
				
				if (typeof worker !== 'undefined') {
					resolve(worker);
				} else {
					reject();
				}
			}, 1000);
		});
	},
 
	onDestroyWorker: function (worker) {
		// async code for destroying the worker expects a promise()
		console.log('[event] emptyworker', worker);
		return new Promise(function (resolve, reject) {
			setTimeout(function () {
				resolve();
			}, 9000);
		});
	},
 
	onFinishedCreatingWorker: function (worker) {
		// called when a worker has been created
	},

	onFinishedCreatingWorkers: function () {
		// called when all workers have been created
	},

	onFinished: function () {
		// called when all jobs are finished
	}
}).then(function () {
	console.log('DONEE');
});

Readme

Keywords

none

Package Sidebar

Install

npm i eque

Weekly Downloads

11

Version

0.0.3

License

ISC

Unpacked Size

581 kB

Total Files

6

Last publish

Collaborators

  • icodeforlove