pausable-timers
v0.1.0
Published
creating timers that can be paused and resumed.
Downloads
309
Readme
pausable-timers
pausable-timers
is a library for creating timers that can be paused and resumed.
Installation
# ✨ Auto-detect
npx nypm install pausable-timers
# npm
npm install pausable-timers
# yarn
yarn add pausable-timers
# pnpm
pnpm install pausable-timers
# bun
bun install pausable-timers
# deno
deno install pausable-timers
Basic Usage
import { pausableTimers } from 'pausable-timers'
const timer = pausableTimers(() => {
/**
* Execute after 1 second
* 1s 后执行
*/
}, 1000, {
mode: 'interval', // 'timeout' | 'interval'
})
timer.pause()
timer.resume()
timer.clear()
timer.reset()
timer.isPaused()
timers.getRemainingTime()
timer.isCompleted() // only for timeout mode
Advanced Usage
Customize the timeout/interval power, like using worker-timers(A replacement for setInterval() and setTimeout() which works in unfocused windows.):
import { pausableTimers } from 'pausable-timers'
import { clearInterval, clearTimeout, setInterval, setTimeout } from 'worker-timers'
const timer = pausableTimers(() => {
/**
* Execute after 1 second
* 1s 后执行
*/
}, 1000, {
setTimeout,
setInterval,
clearTimeout,
clearInterval,
})
Contribution
- Clone this repository
- Install the latest LTS version of Node.js
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run tests using
pnpm dev
orpnpm test
Sponsors
License
Published under the MIT license. Made by @byronogis and community 💛
🤖 auto updated with automd (last updated: Fri Dec 06 2024)