@awkewainze/simpletimer
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

SimpleTimer

A simple wrapper around setTimeout because I like awaitables and I hate rewriting the exact same wrapper for every time.

Example usages

Callback style

function test(): void {
    Timer.for(Duration.fromSeconds(10))
        .addCallback(() => console.log("10 seconds later!"))
        .addCallback(doSomething)
        .start();
}

Awaitable style

async function test(): Promise<void> {
    await Timer.for(Duration.fromSeconds(10)).start().asAwaitable();
    console.log("10 seconds later!");
}

Or shortcut awaitable

async function test(): Promise<void> {
    await Timer.immediateAwaitable(Duration.fromSeconds(10));
    console.log("10 seconds later!");
}

Readme

Keywords

none

Package Sidebar

Install

npm i @awkewainze/simpletimer

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

17.1 kB

Total Files

10

Last publish

Collaborators

  • awkewainze