kochegar
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Kochegar

Simple job queue utility

This library is intended to be used in Typescript projects, but can be built to Javascript and used directly.

What does it do?

It allows you to define tasks and peform jobs on them in an asynchrous manner with concurrency limiting. It can be run indefinitely and doesn't run idle cycles if all jobs are completed.

Configuration

  • concurrency is how many concurrent jobs can be run at a time
  • interval is an interval between batch scheduling

Basic usage

import { Kochegar } from 'kochegar';

const worker = new Kochegar({ concurrency: 10, interval: 1000 });

let sum = 0;
worker.createTask(
    'increment', payload => sum = sum + payload,
);

worker.createTask(
    'decrement', payload => sum = sum - payload,
);

worker.push({ task: 'increment', payload: 10 });
worker.push({ task: 'increment', payload: 20 });
worker.push(
    { task: 'increment', payload: 10 },
    { task: 'increment', payload: 20 },
);
worker.push({ task: 'decrement', payload: 50 });

console.log(worker.jobs());
// 5

console.log(worker.jobs('increment'));
// 4

console.log(worker.jobs('decrement'));
// 1

worker.wait().then(() => {
    console.log(sum);
});

// 10

Dependents (0)

Package Sidebar

Install

npm i kochegar

Weekly Downloads

0

Version

1.2.0

License

ISC

Unpacked Size

26.9 kB

Total Files

8

Last publish

Collaborators

  • ars9