forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timers: setInterval interval includes cb duration
setInterval callback should be scheduled on the interval Fixes: nodejs#7346 PR-URL: nodejs#14815 Fixes: nodejs#7346 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- Loading branch information
Showing
2 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/sequential/test-timers-setInterval-excludes-callback-duration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const Timer = process.binding('timer_wrap').Timer; | ||
const assert = require('assert'); | ||
|
||
let cntr = 0; | ||
let first, second; | ||
const t = setInterval(() => { | ||
common.busyLoop(50); | ||
cntr++; | ||
if (cntr === 1) { | ||
first = Timer.now(); | ||
} else if (cntr === 2) { | ||
second = Timer.now(); | ||
assert(Math.abs(second - first - 100) < 10); | ||
clearInterval(t); | ||
} | ||
}, 100); |