2.0.1 • Published 10 months ago

virtual-timer v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

What is it

It creates only a single timer with specified precision (like a virtual cpu tick), and handles all timeouts and intervals in it.

Pros

  • Performance gain when you set hundreds, thousands, billions of intervals & timeouts.

Cons

  • Performances loss when you set a few intervals & timeouts.

NextJS config

Since the module provided as pure ts files, you need to add this config to your NextJS project:

// next.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {
    transpilePackages: ["virtual-timer"]
};

export default nextConfig;

Usage

import { VirtualTimer } from "virtual-timer";

const virtualTimer = new VirtualTimer();
virtualTimer.timeout(
    (delta) => { console.log(`Timeout running after ${delta} ms`) },
    1000
);
virtualTimer.interval(
    (delta) => { console.log(`Interval running after ${delta} ms`) },
    1000
);

You may specify precision (lower is more precise)

const virtualTimer = new VirtualTimer(5);

You may not use delta:

virtualTimer.timeout(
    () => { console.log("delta is optional") },
    1000
);

You may cancel your timeouts & intervals:

const controller = virtualTimer.timeout(
    () => { console.log("you won't see me") },
    1000
);
controller.cancel()
1.0.7

11 months ago

1.0.6

1 year ago

1.0.5

1 year ago

2.0.1

10 months ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago