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