pausable-timers
is a library for creating timers that can be paused and resumed.
# ✨ 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
import { pausableTimers } from 'pausable-timers'
const timer = pausableTimers({
mode: 'interval', // 'timeout' | 'interval'
args: [() => {
/**
* Execute after 1 second
* 1s 后执行
*/
}, 1000]
})
timer.pause()
timer.resume()
timer.clear()
timer.restart()
timer.isPaused()
timers.getRemainingTime()
timer.isCompleted() // only for timeout mode
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({
setTimeout,
setInterval,
clearTimeout,
clearInterval,
args: [() => {
/**
* Execute after 1 second
* 1s 后执行
*/
}, 1000,]
})
Local development
Published under the MIT license.
Made by @byronogis and community 💛
🤖 auto updated with automd (last updated: Fri Dec 06 2024)