Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ufukbakan/precision-timeout-interval
High precision timeout and interval methods for javascript
https://github.com/ufukbakan/precision-timeout-interval
Last synced: about 2 months ago
JSON representation
High precision timeout and interval methods for javascript
- Host: GitHub
- URL: https://github.com/ufukbakan/precision-timeout-interval
- Owner: ufukbakan
- License: gpl-3.0
- Created: 2022-05-25T13:11:42.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-07T07:41:14.000Z (5 months ago)
- Last Synced: 2024-10-07T12:22:33.044Z (3 months ago)
- Language: JavaScript
- Homepage: https://ufukbakan.github.io/precision-timeout-interval/demo/
- Size: 3.5 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
precision-timeout-interval
Hardware accelerated javascript timing interface.
Click here for live demo
V4 Brings the most developer friendly timing methods
## Installation
```bash
npm i precision-timeout-interval@latest
```## Importing
```js
// ES6:
import { prcTimeout, prcInterval } from 'precision-timeout-interval';
// CommonJS:
const { prcTimeout, prcInterval } = require('precision-timeout-interval');
```## Easy Interface
```js
let timeoutController = prcTimeout(delayInMilliseconds, callbackFunction);
let interval = prcInterval(delayInMilliseconds, callbackFunction);
```
Introducing Awesome V4 Features
- ## Timeouts are now cancellable:
```ts
let myTimeout = prcTimeout(500, () => console.log("I'm gona be cancelled") );
myTimeout.cancel()
```
- ### And of course intervals are too
- # Interval controller is completely changed
## Meet with new interval controller methods: cancel, restart, pauseResume and setPeriod
```ts
let myInterval = prcInterval(100, () => console.log("Hello V4") ); // start
myInterval.pauseResume(); // pause
myInterval.pauseResume(); // resume
myInterval.restart(); // restart counter
myInterval.setPeriod(1000); // set a new period and restart
myInterval.cancel() // stop
```## WithDelta Support Since V3.0.0
Timers and Intervals can autobind delta time if you wish as callback parameter.
Usefull especially for game developers.
```ts
prcTimeoutWithDelta(50, (deltaT) =>{
console.log("Hello, after "+ deltaT +" msecs");
});
```