control-c
v0.0.9
Published
Control-C (SIGINT) handler supports single, double, triple, quadruple control-c and so on
Downloads
15
Maintainers
Readme
control-c - npm
ControlC is simple utility, handles SIGINT or Control-C. Also suppot single control-c, double control-c, triple control-c and so on.
For example, print current status on single control-c, reset or re-initialize on double control-c, clean up and exit on triple control-c, ignore quadruple or more control-c, and so on.
INSTALL:
$ npm install control-c
USAGE:
var ControlC = require('control-c');
method: ControlC.new(handlers...)
Add new handlers to handle SIGINT (Control-C).
Format
var c1 = new ControlC(
function singleControlC() { console.log('single ctrl-c'); },
function doubleControlC() { console.log('double ctrl-c'); },
function tripleControlC() { console.log('triple ctrl-c'); this.remove(); },
function ignoreControlC() {});
// or
var c2 = ControlC(
function singleControlC() { console.log('single ctrl-c'); },
function doubleControlC() { console.log('double ctrl-c'); },
function tripleControlC() { console.log('triple ctrl-c'); this.remove(); },
function ignoreControlC() {});
// or
var c3 = ControlC.new(
function singleControlC() { console.log('single ctrl-c'); },
function doubleControlC() { console.log('double ctrl-c'); },
function tripleControlC() { console.log('triple ctrl-c'); this.remove(); },
function ignoreControlC() {});
Parameters
- handlers...: SIGINT handler functions, required
Returns
ControlC instance.
method: this.remove() and this.add()
Remove and add to hande SIGINT.
Format
var c1 = new ControlC(function () {},
function () { this.remove(); });
c1.remove();
c1.add();
property: ControlC.interval
Control-C timeout interval. milliseconds.
Format
ControlC.interval = 400;
console.log(ControlC.interval);
Parameters
- interval: Control-C timeout interval, between 200 and 2000 msec, default 400 msec
EXAMPLE:
'use strict';
var ControlC = require('control-c');
var singleCount = 0;
var doubleCount = 0;
ControlC(
function singleControlC() { console.log('Single:', ++singleCount); },
function doubleControlC() { console.log('Double:', ++doubleCount); },
function tripleControlC() { console.log('Reset'); singleCount = doubleCount = 0; },
function quadrupleControlC() { console.log('Exit'); process.nextTick(process.exit); },
function ignoreControlC() {});
console.log('press control-c in 30 seconds.');
setTimeout(function () {}, 30000);
LICENSE:
MIT