0.2.0 • Published 7 months ago

pausable-timers v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

pausable-timers

npm version npm downloads bundle size codecov license

JSDocs

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({
  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

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({
  setTimeout,
  setInterval,
  clearTimeout,
  clearInterval,
  args: [() => {
    /**
     * Execute after 1 second
     * 1s 后执行
     */
  }, 1000,]
})

Sponsors

License

Published under the MIT license. Made by @byronogis and community 💛


🤖 auto updated with automd (last updated: Sat Dec 28 2024)

0.2.0

7 months ago

0.1.0

7 months ago

0.0.3

7 months ago

0.0.2

8 months ago

0.0.1

8 months ago