1.0.0 • Published 3 years ago

@awkewainze/simpletimer v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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!");
}