0.1.0 • Published 7 years ago

graceful-timer v0.1.0

Weekly downloads
4
License
-
Repository
github
Last release
7 years ago

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