Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ufukbakan/virtual-timer
A single timer virtually runs other timers
https://github.com/ufukbakan/virtual-timer
Last synced: about 2 months ago
JSON representation
A single timer virtually runs other timers
- Host: GitHub
- URL: https://github.com/ufukbakan/virtual-timer
- Owner: ufukbakan
- Created: 2023-06-28T00:31:09.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-08-07T07:50:39.000Z (5 months ago)
- Last Synced: 2024-10-06T19:07:15.420Z (3 months ago)
- Language: TypeScript
- Size: 94.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Virtual Timers
## 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:
```js
// next.config.mjs/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ["virtual-timer"]
};export default nextConfig;
```
## Usage
```ts
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)
```ts
const virtualTimer = new VirtualTimer(5);
```
You may not use delta:
```ts
virtualTimer.timeout(
() => { console.log("delta is optional") },
1000
);
```
You may cancel your timeouts & intervals:
```ts
const controller = virtualTimer.timeout(
() => { console.log("you won't see me") },
1000
);
controller.cancel()
```