function startCron(interval, listener) {
const now = Date.now();
let nextTick;
do {
nextTick = interval.next().getTime();
} while (now >= nextTick);
setTimeout(() => {
listener();
startCron(interval, listener);
}, nextTick - now);
}
这个 do...while 是干嘛的
1
atian25 2017-06-12 10:40:59 +08:00
`interval.next().getTime()` 有可能比当前时间晚,所以要一直获取直到第一个可用时间
|