JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q52383F
  • License MIT

Control-C (SIGINT) handler supports single, double, triple, quadruple control-c and so on

Package Exports

  • control-c

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (control-c) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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, and so on.

Japanese version/■日本語版はこちら■

control-c.png

INSTALL:

$ npm install control-c

USAGE:

var ControlC = require('control-c');

method: ControlC.new(handlers...)

Add new handlers to handle SIGINT.

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(); });

// 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(); });

// 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(); });

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 = 500;
console.log(ControlC.interval);

Parameters

  • interval: Control-C timeout interval, between 200 and 2000 msec, default 500 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); });

console.log('press control-c in 30 seconds.');
setTimeout(function () {}, 30000);

LICENSE:

MIT