https://github.com/dandre3000/fixed-time-step
Call a function on a fixed interval over a variable timespan.
https://github.com/dandre3000/fixed-time-step
Last synced: 3 months ago
JSON representation
Call a function on a fixed interval over a variable timespan.
- Host: GitHub
- URL: https://github.com/dandre3000/fixed-time-step
- Owner: dandre3000
- License: mit
- Created: 2026-03-20T18:21:04.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-03-20T18:25:00.000Z (3 months ago)
- Last Synced: 2026-03-21T09:39:25.849Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fixed-time-step
Call a function on a fixed interval over a variable timespan.
## Installation
npm i @dandre3000/fixed-time-step
## Usage
```js
import { FixedTimeStep } from '@dandre3000/fixed-time-step'
const fts = new FixedTimeStep(1000 / 60, (t, ...args) => {
console.log(t, elapsedTime, i, ...args) // 1000 / 60, ...
elapsedTime += t
i++
})
let time = performance.now()
let elapsedTime = 0
let i = 0
setInterval(() => {
const dt = performance.now() - time
fts.step(dt, { args: ['YOOO'] })
time = performance.now()
})
```
## Exports
interface StepOptions {
args: boolean
self: boolean
}
### Class FixedTimeStep
#### constructor (interval: number, callback: (...args: any[]) => void)
### Instance
#### interval: number
#### callback: (...args: any[]) => void
#### step (time: number, options?: StepOptions) => number
## License
[MIT](https://github.com/dandre3000/async-keyboard-pointer/blob/main/LICENSE)