Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

signalmanager

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

signalmanager

ES6 JS class to capture exit signals and specify callbacks to accept or deny them

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

signalmanager

ES6 JS classes for socket client and server message passing

Installation

npm install signalmanager --save

Usage

Prevent closing until your code approves it

Add shutdown handlers for SIGINT and SIGTERM.
This is in case multiple "threads" or classes need to
do individual checks before closing. (Obviously no program can withstand SIGKILL though)

Add a request handler first. It will be responsible for passing into the
callback true or false for if it approves the shutdown.
If all processes approve, all shutdown handlers are run then exited.
If any function/class passes false for REJECTION, the shutdown is canceled;
and no shutdown handlers are run.


// SignalManager singleton. Should be same variable required anywhere
var SignalManager = require('signalmanager');

// APPROVAL HANDLER
// Generally the idea is that each service should have a shutdown approval handler to
// ask each service before shutting down if it can safely
SignalManager.addShutdownApprovalHandler(() => {
  if (somethingImportantHasNotFinishedYet) {
    return false; // do not approve shutdown. will cancel node program shutdown
  } else {
    return true; // will allow next handlers to run and if all approve, move on to the ShutdownHandlers
  }
});

// SHUTDOWN HANDLER
// If all the approvalHandlers returned true, shutdown will begin. All shutdownHandlers
// will be called in order of adding. Generally
SignalManager.addShutdownHandler(() => {
  if (isAnEmergencySomethingImportantIsStillRunning) {
    // false here as opposed to in the approval handler probably signifies something important
    // because by this point, other of the shutdown handlers may have run
    return false; // do not approve shutdown. will cancel program shutdown
  } else {
    // these are examples of what you would do
    someSocket.close();
    someFile.close();
    someEmail.send();

    return true; // will allow next handlers to run. Upon all returning true, it will allow exit
  }
});


Credits

http://c-cfalcon.rhcloud.com

Keywords

FAQs

Package last updated on 25 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc