https://github.com/wotschofsky/better-timer
Reusable timer class library that supports both promises and multiple callbacks and is most importantly pauseable.
https://github.com/wotschofsky/better-timer
Last synced: 5 months ago
JSON representation
Reusable timer class library that supports both promises and multiple callbacks and is most importantly pauseable.
- Host: GitHub
- URL: https://github.com/wotschofsky/better-timer
- Owner: wotschofsky
- License: mit
- Created: 2020-06-24T23:04:14.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-05T20:22:20.000Z (about 1 year ago)
- Last Synced: 2024-11-20T06:51:37.581Z (5 months ago)
- Language: TypeScript
- Homepage:
- Size: 825 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - wotschofsky/better-timer - Reusable timer class library that supports both promises and multiple callbacks and is most importantly pauseable. (TypeScript)
README
[](https://www.npmjs.com/package/better-timer)
# better-timer
Timer class that supports both promises and multiple callbacks.
## Installation
Add the script to your project through a package manager:
`$ npm i better-timer`
or
`$ yarn add better-timer`
Alternatively you can also import the script found in the releases section on GitHub directly. If you choose this option you won't need to use imports going forward - everything will all be available to you automatically.
```html
```
Or include through a public CDN:
```html
```
## General Api
```javascript
new Timer(duration, ...callbacks)
```## Code example
```javascript
import Timer from 'better-timer';
// OR
const Timer = require('better-timer');// Duration in Milliseconds
const duration = 1000;const timer = new Timer(duration, () => {
// Callbacks are optional
console.log('Callback executed!');
});// Get promise and add "then" block
timer.promise.then(() => {
console.log('Promise resolved!');
});// Pause timer
timer.pause();// Resume timer
timer.resume();// Cancel timer
timer.cancel();
```