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

0.1.3 • Public • Published

atdis

A simple abstract task dispatching library.

Usage

import {Scheduler, Worker} from "atdis";
const scheduler = new Scheduler<string>();
const worker = new Worker(scheduler);
worker.start();

// Tasks are slow async functions.
function download(name: string): Promise<string> {
    return new Promise(resolve => {
        setTimeout(() => resolve(`Hello ${name}!`), 500);
    })
}

// A scheduler uses priority queues to order tasks.
const task = scheduler.schedule(download, {data: 'world'});
const task2 = scheduler.schedule(download, {
    data: 'world',
    retries: 5     // If the task fails, it can be rescheduled transparently.
});

// Tasks can be awaited on.
const data = await task;

Readme

Keywords

none

Package Sidebar

Install

npm i atdis

Weekly Downloads

3

Version

0.1.3

License

MIT

Unpacked Size

36 kB

Total Files

19

Last publish

Collaborators

  • eth-p