Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bergos/interval-as-class
setTimeout as a class
https://github.com/bergos/interval-as-class
Last synced: about 2 months ago
JSON representation
setTimeout as a class
- Host: GitHub
- URL: https://github.com/bergos/interval-as-class
- Owner: bergos
- Created: 2020-08-08T00:47:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-08T00:47:34.000Z (over 4 years ago)
- Last Synced: 2024-11-20T07:25:24.459Z (2 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# interval-as-class
`setTimeout`, just as a class.
## Usage
The package exports the `Interval` class as default export.
### Interval(func, time, { aligned, offset, start})
Creates a new `Interval` instance.
The following arguments are supported:- `func`: The function that should be called at each interval
- `time`: The time between each function call in milliseconds
- `aligned`: If `true`, aligns the time of the function calls when `Date.now() % time` is close to zero (default: `false`)
- `offset`: If `aligned` is `true`, this value will be used as offset to the aligned time (default: `0`)
- `start`: If `true`, the `Interval` will start immediately without calling `start()`### start()
Starts calling the function at the given intervals.
### stop()
Stops calling the function.