开发者社区> 镜像站> NPM> set-interrupt
set-interrupt
Interruptible timer
Last updated 6 months ago by emilbayes .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install set-interrupt 
SYNC missed versions from official npm registry.

set-interrupt

Build Status

Interruptible timer

Usage

var { setInterrupt, clearInterrupt } = require('set-interrupt')

var i = setInterrupt(function (err, val) {
  console.log('Hello world')
}, 1000)

// Never calls the callback
clearInterrupt(i)
// or
i.interrupt()

// Calls the callback with an error
clearInterrupt(i, new Error('Failed'))
// or
i.interrupt(new Error('Failed'))

// Calls the callback with a value
clearInterrupt(i, null, 'ok')
// or
i.interrupt(null, 'ok')

API

const itr = setInterrupt(cb, time)

Creates a new interrupt

itr.interrupt([err], [val])

Cancels the interrupt timer. If you pass err or val, the callback is invoked like a standard Node.js callback. Otherwise the callback is simply ignored. If the timer has already been invoked, this becomes a noop

clearInterrupt(itr, [err], [val])

Convenience for the above, but behaves like clearTimeout, ignoring itr that is not an interrupt

Install

npm install set-interrupt

License

ISC

Current Tags

  • 1.0.1                                ...           latest (6 months ago)

1 Versions

  • 1.0.1                                ...           6 months 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)
Dependents (0)
None