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

0.1.4 • Public • Published

tardy

Turn promises into progress reporting processes in a functional/monadic style.

Requires ES modules.

Quickstart

import { Tardy } from 'tardy'

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
const process = (min: number, max: number) => delay(Math.random() * (max - min) + min);
const increments = (count: number) => Array.from({ length: count }, (_, i) => i);

const sample = new Tardy(async client => {
    await Tardy.reportCountdown(5).run(client);

    await Tardy.seq(increments(10).map(n => 
        new Tardy(() => process(100, 500)).report(`Doing ${n}`)
    )).report('Sequence', 0, .5).run(client);

    await Tardy.all(increments(100).map(n => 
        new Tardy(() => process(1000, 5000)).report()
    )).report('Parallel', 0.5, 1).run(client);

    client.log('Done'); 
});

sample.exec().then(() => 
    sample.exec({ multiline: false })
);

Readme

Keywords

none

Package Sidebar

Install

npm i tardy

Weekly Downloads

1

Version

0.1.4

License

ISC

Unpacked Size

12.4 kB

Total Files

14

Last publish

Collaborators

  • jsoldi