-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timers: add internal [@@ refresh()] function
Hidden via a symbol because I'm unsure exactly what the API should look like in the end. Removes the need to use _unrefActive for efficiently refreshing timeouts. It still uses it under the hood but that could be replaced with insert() directly if it were in the same file. PR-URL: #18065 Reviewed-By: Anatoli Papirovski <[email protected]>
- Loading branch information
1 parent
54fe0a6
commit bb5575a
Showing
5 changed files
with
90 additions
and
13 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
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
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
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
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,59 @@ | ||
// Flags: --expose-internals | ||
|
||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const { strictEqual } = require('assert'); | ||
const { setUnrefTimeout, refreshFnSymbol } = require('internal/timers'); | ||
|
||
// Schedule the unrefed cases first so that the later case keeps the event loop | ||
// active. | ||
|
||
// Every case in this test relies on implicit sorting within either Node's or | ||
// libuv's timers storage data structures. | ||
|
||
// unref()'d timer | ||
{ | ||
let called = false; | ||
const timer = setTimeout(common.mustCall(() => { | ||
called = true; | ||
}), 1); | ||
timer.unref(); | ||
|
||
// This relies on implicit timers handle sorting withing libuv. | ||
|
||
setTimeout(common.mustCall(() => { | ||
strictEqual(called, false, 'unref()\'d timer returned before check'); | ||
}), 1); | ||
|
||
timer[refreshFnSymbol](); | ||
} | ||
|
||
// unref pooled timer | ||
{ | ||
let called = false; | ||
const timer = setUnrefTimeout(common.mustCall(() => { | ||
called = true; | ||
}), 1); | ||
|
||
setUnrefTimeout(common.mustCall(() => { | ||
strictEqual(called, false, 'unref pooled timer returned before check'); | ||
}), 1); | ||
|
||
timer[refreshFnSymbol](); | ||
} | ||
|
||
// regular timer | ||
{ | ||
let called = false; | ||
const timer = setTimeout(common.mustCall(() => { | ||
called = true; | ||
}), 1); | ||
|
||
setTimeout(common.mustCall(() => { | ||
strictEqual(called, false, 'pooled timer returned before check'); | ||
}), 1); | ||
|
||
timer[refreshFnSymbol](); | ||
} |