-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: #7346 PR-URL: #14815 Fixes: #7346 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
- 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); |