MDN 说明
Ensure that execution duration is shorter than interval frequency If there is a possibility that your logic could take longer to execute than the interval time, it is recommended that you recursively call a named function using setTimeout(). For example, if using setInterval() to poll a remote server every 5 seconds, network latency, an unresponsive server, and a host of other issues could prevent the request from completing in its allotted time. As such, you may find yourself with queued up XHR requests that won t necessarily return in order.
因此,一 4个样本
let start;
let count = 1;
setInterval(() => {
let b = 0;
for (let i = 0; i < 100000000; i++) {
b += i;
}
if (!start) start = performance.now();
else console.log((performance.now() - start) / count++);
}, 200);
let start;
let count = 1;
setInterval(() => {
let b = 0;
for (let i = 0; i < 100000000; i++) {
b += i;
}
if (!start) start = performance.now();
else console.log((performance.now() - start) / count++,b);
}, 200);
function mySetinterval(fn, timeout, ...args) {
let timer;
function loop() {
timer = setTimeout(() => {
fn(...args);
loop();
}, timeout);
}
loop();
return function () {
clearTimeout(timer);
timer = null;
};
}
let start;
let count = 1;
mySetinterval(() => {
let b = 0;
for (let i = 0; i < 100000000; i++) {
b += i;
}
if (!start) start = performance.now();
else console.log((performance.now() - start) / count++);
}, 200);
function mySetinterval(fn, timeout, ...args) {
let timer;
function loop() {
timer = setTimeout(() => {
fn(...args);
loop();
}, timeout);
}
loop();
return function () {
clearTimeout(timer);
timer = null;
};
}
let start;
let count = 1;
mySetinterval(() => {
let b = 0;
for (let i = 0; i < 100000000; i++) {
b += i;
}
if (!start) start = performance.now();
else console.log((performance.now() - start) / count++,b);
}, 200);
我认为, 平均实际执行所有法典,因此下游动物在200米后会发生。
和 及时性将执行所有法典,而时段的缺口将可能与编码脱钩,即通过pu法进行估算。
是否正确? 而我不理解为什么国际发展部说XHR会影响Interval,你会举一个例子吗?