0.0.2-beta.4 • Published 1 month ago

qrun v0.0.2-beta.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

QRun

npm npm npm

Lightweight and easy-to-use JavaScript library for managing queues efficiently.

Table of Contents

Installation

Install with npm

npm install qrun

Usage

JavaScript

import { qrun } from 'qrun';

const queue = qrun.createQueue((params, done, stop) => {
	if (params === 5) {
		throw new Error('error 5');
	}
	if (params === 7) {
		return stop();
	}
	done(params);
});

for (let i = 0; i < 10; i++) {
	queue.add(i, { cooldown: 100 });
}

queue.finishAdding(); // optional

queue.onDone(console.log);
queue.onError(console.error);

queue.whenFinalised(() => console.log('end'));
queue.whenStopped(() => console.log('stopped'));

console.log(qrun.getAllQueues());
console.log(qrun.getQueue(queue.uuid));

TypeScript

import { qrun } from 'qrun';

const queue = qrun.createQueue<number, number, Error>((params, done, stop) => {
	if (params === 5) {
		throw new Error('error 5');
	}
	if (params === 7) {
		return stop();
	}
	done(params);
});

API

QRun object

createQueue()

Creates a new QRun queue.

Args:

  • callback(params, done, stop): A callback that will execute QRun while the queue is executing.
  • options: - options.save: Enable or disable queue saving in QRun storage. Default 'true'. The following methods of the QRun object will not work if saving is disabled.

getQueue()

Get queue by uuid.

Args:

  • queueUUID: queue uuid.

getAllQueues()

Get all queues.

stopQueue()

Stop queue by uuid.

stopAllQueues()

Stop all queues.

Queue object

uuid

Unique queue identifier. Required for working with QRun storage.

add()

Adding parameters to perform a queue callback.

Args:

  • params: Any data. String, Object, etc.
  • options: - options.cooldown: Setting an artificial delay in milliseconds for queue execution. Optional.

finishAdding()

Finish adding parameters. After calling this method, you can no longer add new parameters. When the execution of the last added parameter is complete, the whenFinalised() callback will be triggered.

stop()

Stop queue.

onDone()

Listen for done() events.

Args:

onError()

Catching errors.

Args:

  • callback(error): A callback that will execute QRun during an error.

whenStopped()

Listening for a `stop' event. It is triggered only once.

Args:

whenFinalised()

Listening for a `final' event. It is triggered only once.

Args:

  • callback(): A callback that will only execute QRun after calling finishAdding().

Contributing

Clone repo, run npm install to install all dependencies.

Thank you for considering contributing. :)

Author

DevSnippets - @devsnippets

0.0.2-beta.4

1 month ago

0.0.2-beta.3

2 months ago

0.0.2-beta.1

2 months ago

0.0.2-beta.2

2 months ago

0.0.1-beta.5

2 months ago

0.0.1-beta.4

2 months ago

0.0.1-beta.3

2 months ago

0.0.1-beta.2

2 months ago

0.0.1-beta.1

2 months ago