Skip to content

Commit

Permalink
chore: use safetimers max interval
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 committed Jun 5, 2017
1 parent da212ac commit a84ff63
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const loadSchedule = require('./lib/load_schedule');
const parser = require('cron-parser');
const ms = require('humanize-ms');
const safetimers = require('safe-timers');
const MAX_SAFE_TIME = Math.pow(2, 31) - 1;
const SCHEDULE_HANDLER = Symbol.for('egg#scheduleHandler');

module.exports = agent => {
Expand Down Expand Up @@ -106,15 +105,15 @@ function startCron(interval, listener) {
}

function safeTimeout(fn, delay, ...args) {
if (delay >= MAX_SAFE_TIME) {
if (delay >= safetimers.maxInterval) {
setTimeout(fn, delay, ...args);
} else {
safetimers.setTimeout(fn, delay, ...args);
}
}

function safeInterval(fn, delay, ...args) {
if (delay >= MAX_SAFE_TIME) {
if (delay >= safetimers.maxInterval) {
setInterval(fn, delay, ...args);
} else {
safetimers.setInterval(fn, delay, ...args);
Expand Down

0 comments on commit a84ff63

Please sign in to comment.