Socket
Book a DemoInstallSign in
Socket

failsafe

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

failsafe

Run a callback regardless after a timeout

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

failsafe

Ensures a callback function gets called, one way or another. Use in situations where continuing is more important than the result of the callback. I generally incorporate this into my shutdown / restart procedure.

Install

npm install --save-dev failsafe

Usage

// Failsafe code - will definitely exit in 15 seconds or less.
var failsafe = require('failsafe');
database.close(failsafe(5000, function(){
  server.close(failsafe(10000, function(){
    console.log('Server shutdown');
    process.exit();
  })
})

// Original code - might not ever exit
database.close(function(){
  server.close(function(){
    console.log('Server shutdown');
    process.exit();
  })
})

How it works

It's so simple, I'll put the source code right here:

// failsafe.js
var once = require('once');

module.exports = function(delay, callback) {
  callback = once(callback);
  setTimeout(callback, delay);
  return callback;
};

Contributing

Pull requests welcome!

Keywords

callback

FAQs

Package last updated on 15 Feb 2016

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.