You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
zhangzifa opened this issue
Jun 23, 2016
· 3 comments
Labels
duplicateIssues and PRs that are duplicates of other issues or PRs.timersIssues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
When set a timer by function setInterval with a certain interval (e.g 1000ms) , the execute time of the callback is another value (e.g 500ms).
The real interval between two callbacks is 1000 + 500 + 500ms.
It is more reasonable that the real interval is 1000 + 500ms.
Code example:
// function sleep mocks some real logic that executed cost a certain time. constsleep=function(milliSeconds){varstartTime=newDate().getTime();while(newDate().getTime()<startTime+milliSeconds);};conststart=newDate();varlast=start;varinterval=setInterval(function(){varnow=newDate();console.log('timer callback from start '+(now-start)+'ms '+'from last callback '+(now-last)+'ms');last=now;sleep(500);},1000);
The output is something like this:
timer callback from start 1537ms from last callback 1537ms
timer callback from start 3540ms from last callback 2003ms
timer callback from start 5543ms from last callback 2003ms
timer callback from start 7545ms from last callback 2002ms
timer callback from start 9546ms from last callback 2001ms
timer callback from start 11548ms from last callback 2002ms
timer callback from start 13549ms from last callback 2001ms
timer callback from start 15550ms from last callback 2001ms
When change the logic of listOnTimeout:
functionlistOnTimeout(){varmsecs=this.msecs;varlist=this;debug('timeout callback %d',msecs);varnow=Timer.now();debug('now: %s',now);vardiff,first,threw;while(first=L.peek(list)){diff=now-first._idleStart;if(diff<msecs){list.start(msecs-diff,0);=====>>>>>list.start(msecs,0);debug('%d list wait because diff is %d',msecs,diff);return;}else{
...
The output of the code example:
timer callback from start 1703ms from last callback 1703ms
timer callback from start 3207ms from last callback 1504ms
timer callback from start 4707ms from last callback 1500ms
timer callback from start 6207ms from last callback 1500ms
timer callback from start 7708ms from last callback 1501ms
timer callback from start 9210ms from last callback 1502ms
timer callback from start 10711ms from last callback 1501ms
The text was updated successfully, but these errors were encountered:
Fishrock123
added
the
timers
Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
label
Jun 23, 2016
duplicateIssues and PRs that are duplicates of other issues or PRs.timersIssues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
When set a timer by function
setInterval
with a certain interval (e.g 1000ms) , the execute time of the callback is another value (e.g 500ms).The real interval between two callbacks is 1000 + 500 + 500ms.
It is more reasonable that the real interval is 1000 + 500ms.
Code example:
The output is something like this:
When change the logic of listOnTimeout:
The output of the code example:
The text was updated successfully, but these errors were encountered: