Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zkochan/kamikaze
Making functions self destructing in a few seconds if not executed.
https://github.com/zkochan/kamikaze
Last synced: 29 days ago
JSON representation
Making functions self destructing in a few seconds if not executed.
- Host: GitHub
- URL: https://github.com/zkochan/kamikaze
- Owner: zkochan
- License: mit
- Created: 2015-07-29T16:32:25.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-03T09:13:00.000Z (about 7 years ago)
- Last Synced: 2024-11-25T07:43:12.601Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kamikaze
A callback wrapper that executes it with a timeout error if not called in time.
[![Dependency Status](https://david-dm.org/zkochan/kamikaze/status.svg?style=flat)](https://david-dm.org/zkochan/kamikaze)
[![Build Status](https://travis-ci.org/zkochan/kamikaze.svg?branch=master)](https://travis-ci.org/zkochan/kamikaze)
[![npm version](https://badge.fury.io/js/kamikaze.svg)](http://badge.fury.io/js/kamikaze)
[![Coverage Status](https://coveralls.io/repos/github/zkochan/kamikaze/badge.svg?branch=master)](https://coveralls.io/github/zkochan/kamikaze?branch=master)## Installation
```
npm install --save kamikaze
```## Usage
```js
var kamikaze = require('kamikaze')var cb = kamikaze(5000, function(err, msg) {
if (err) {
// if no message was passed for 5 seconds, just output 'Hello world!'
console.log('Hello world!')
return
}console.log(msg)
})// ...if called in less than 5 seconds, this will output 'Just in time!'
cb(null, 'Just in time!')// to cancel the callback timer just clear it
clearTimeout(cb.timeoutId)
```## License
MIT © [Zoltan Kochan](https://www.kochan.io)