1.2.0 • Published 5 years ago

kochegar v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

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
1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.10.0

5 years ago

0.9.4

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago