Skip to content

Commit 9e8c9be

Browse files
committed
timers: rename validateTimerDuration to getTimerDuration
The function did not only validate the timer but it caused side effects like a warning and potentially returned a different value than the input value. Thus the name `validate` did not seem to be appropriate. PR-URL: #26809 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6c913fb commit 9e8c9be

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

lib/_http_client.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const {
4545
ERR_INVALID_PROTOCOL,
4646
ERR_UNESCAPED_CHARACTERS
4747
} = require('internal/errors').codes;
48-
const { validateTimerDuration } = require('internal/timers');
48+
const { getTimerDuration } = require('internal/timers');
4949
const is_reused_symbol = require('internal/freelist').symbols.is_reused_symbol;
5050
const {
5151
DTRACE_HTTP_CLIENT_REQUEST,
@@ -146,7 +146,7 @@ function ClientRequest(input, options, cb) {
146146
this.socketPath = options.socketPath;
147147

148148
if (options.timeout !== undefined)
149-
this.timeout = validateTimerDuration(options.timeout, 'timeout');
149+
this.timeout = getTimerDuration(options.timeout, 'timeout');
150150

151151
var method = options.method;
152152
var methodIsString = (typeof method === 'string');
@@ -743,7 +743,7 @@ ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) {
743743
}
744744

745745
listenSocketTimeout(this);
746-
msecs = validateTimerDuration(msecs, 'msecs');
746+
msecs = getTimerDuration(msecs, 'msecs');
747747
if (callback) this.once('timeout', callback);
748748

749749
if (this.socket) {

lib/internal/stream_base_commons.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
2121
const {
2222
kTimeout,
2323
setUnrefTimeout,
24-
validateTimerDuration
24+
getTimerDuration
2525
} = require('internal/timers');
2626

2727
const kMaybeDestroy = Symbol('kMaybeDestroy');
@@ -205,7 +205,7 @@ function setStreamTimeout(msecs, callback) {
205205
this.timeout = msecs;
206206

207207
// Type checking identical to timers.enroll()
208-
msecs = validateTimerDuration(msecs, 'msecs');
208+
msecs = getTimerDuration(msecs, 'msecs');
209209

210210
// Attempt to clear an existing timer in both cases -
211211
// even if it will be rescheduled we don't want to leak an existing timer.

lib/internal/timers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ function setUnrefTimeout(callback, after) {
359359
}
360360

361361
// Type checking used by timers.enroll() and Socket#setTimeout()
362-
function validateTimerDuration(msecs, name) {
362+
function getTimerDuration(msecs, name) {
363363
validateNumber(msecs, name);
364364
if (msecs < 0 || !isFinite(msecs)) {
365365
throw new ERR_OUT_OF_RANGE(name, 'a non-negative finite number', msecs);
@@ -586,7 +586,7 @@ module.exports = {
586586
kRefed,
587587
initAsyncResource,
588588
setUnrefTimeout,
589-
validateTimerDuration,
589+
getTimerDuration,
590590
immediateQueue,
591591
getTimerCallbacks,
592592
immediateInfoFields: {

lib/timers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const {
3636
},
3737
kRefed,
3838
initAsyncResource,
39-
validateTimerDuration,
39+
getTimerDuration,
4040
timerListMap,
4141
timerListQueue,
4242
immediateQueue,
@@ -102,7 +102,7 @@ function unenroll(item) {
102102
// This function does not start the timer, see `active()`.
103103
// Using existing objects as timers slightly reduces object overhead.
104104
function enroll(item, msecs) {
105-
msecs = validateTimerDuration(msecs, 'msecs');
105+
msecs = getTimerDuration(msecs, 'msecs');
106106

107107
// If this item was already in a list somewhere
108108
// then we should unenroll it from that

0 commit comments

Comments
 (0)