Type Alias Stopwatch

Stopwatch: {
    elapsed: (() => number);
    reset: (() => void);
    start: (() => void);
    stop: (() => void);
}

Allows you to time operations.

Type declaration

  • elapsed: (() => number)

    Tries to get the elapsed ms. Throws if the Stopwatch has not been started.

      • (): number
      • Returns number

        Usage

        const w = watch();

        w.start();

        await sleep(1000);

        // you don't have to call stop before accessing `.elapsed()`
        console.log(w.elapsed()); // 1000
  • reset: (() => void)

    Reset the stopwatch.

      • (): void
      • Returns void

        Usage

        const w = stopwatch();

        w.start();

        w.stop();

        w.reset();

        w.elapsed(); // Error: "Call `.start()` first!"
  • start: (() => void)

    Start the stopwatch.

      • (): void
      • Returns void

        Usage

        const w = stopwatch();

        w.start(); // start counting
  • stop: (() => void)

    Stop the stopwatch.

      • (): void
      • Returns void

        Usage

        const w = stopwatch();

        w.start();

        await sleep(1000);

        w.stop(); // stop counting

        await sleep(1000);

        console.log(w.elapsed()); // 1000