timeout-refresh
Efficiently refresh a timer
Last updated 3 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install timeout-refresh 
SYNC missed versions from official npm registry.

timeout-refresh

Efficiently refresh a timer

npm install timeout-refresh

Uses timeout.refresh in Node. In the browser a basic clearTimeout + setTimeout is used since no other method exists

Usage

const Timeout = require('timeout-refresh')

const to = Timeout.once(100, function () {
  console.log('Timed out!')
})

const i = setInterval(function () {
  // refresh every 50ms
  to.refresh()
}, 50)

setTimeout(function () {
  // cancel the refresh after 500ms
  clearInterval(i)
  setTimeout(function () {
    console.log('Should have timed out now')
  }, 200)
}, 500)

API

to = Timeout.once(ms, ontimeout, [context])

Make a new refreshable timeout that fires once.

If you pass context, it will be set as this when calling ontimeout.

to = Timeout.on(ms, ontimeout, [context])

Make a new refreshable timeout that fires every ms.

If you pass context, it will be set as this when calling ontimeout.

to.unref()

Unref the timer.

to.ref()

Ref the timer.

to.refresh()

Refresh the timeout.

to.destroy()

Destroy the timeout.

License

MIT

Current Tags

  • 2.0.1                                ...           latest (3 years ago)

6 Versions

  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |