graceful-timer

0.1.0 • Public • Published

graceful-timer

NPM version npm download

Graceful timer for catch errors. I make this module bacause i come across some problems when i try to run some isomophic code on the nodejs server. Some code maybe makes sense in the browser, but dangrous in server environment, for example:

try {
  xxx
} catch (e) {
  // for some purposes, we do asychronous error thrown
  setTimeout(function() {
    throw e;
  }, 0);
}

API

Just use as the same as the original global timers api. The only thing this module does is wrap the callback with try catch.

  • setTimeout

  • setInterval

  • setImmediate

  • setLogger It will use global.console as default logger. However, you can customize your own logger only if the .error method is provided.

const { setLogger } = require('graceful-timer');
 
setLogger({
  error(stack) {
    // make a http request to upload error info
    uploadErrorInfo(stack);
 
    // fileLogger.writeLog(stack);
  }
});

Lisence

MIT

Package Sidebar

Install

npm i graceful-timer

Weekly Downloads

2

Version

0.1.0

License

none

Last publish

Collaborators

  • luckydrq