Skip to content

Commit d458cd7

Browse files
VoltrexKeyvatargos
authored andcommitted
typings: add JSDoc typings for timers
Added JSDoc typings for the `timers` lib module. PR-URL: #38834 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent c915a1b commit d458cd7

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

lib/timers.js

+47-4
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,16 @@ function enroll(item, msecs) {
127127
}
128128

129129

130-
/*
131-
* DOM-style timers
130+
/**
131+
* Schedules the execution of a one-time `callback`
132+
* after `after` milliseconds.
133+
* @param {Function} callback
134+
* @param {number} [after]
135+
* @param {any} [arg1]
136+
* @param {any} [arg2]
137+
* @param {any} [arg3]
138+
* @returns {Timeout}
132139
*/
133-
134140
function setTimeout(callback, after, arg1, arg2, arg3) {
135141
validateCallback(callback);
136142

@@ -170,6 +176,11 @@ ObjectDefineProperty(setTimeout, customPromisify, {
170176
}
171177
});
172178

179+
/**
180+
* Cancels a timeout.
181+
* @param {Timeout | string | number} timer
182+
* @returns {void}
183+
*/
173184
function clearTimeout(timer) {
174185
if (timer && timer._onTimeout) {
175186
timer._onTimeout = null;
@@ -185,6 +196,16 @@ function clearTimeout(timer) {
185196
}
186197
}
187198

199+
/**
200+
* Schedules repeated execution of `callback`
201+
* every `repeat` milliseconds.
202+
* @param {Function} callback
203+
* @param {number} [repeat]
204+
* @param {any} [arg1]
205+
* @param {any} [arg2]
206+
* @param {any} [arg3]
207+
* @returns {Timeout}
208+
*/
188209
function setInterval(callback, repeat, arg1, arg2, arg3) {
189210
validateCallback(callback);
190211

@@ -215,6 +236,11 @@ function setInterval(callback, repeat, arg1, arg2, arg3) {
215236
return timeout;
216237
}
217238

239+
/**
240+
* Cancels an interval.
241+
* @param {Timeout | string | number} timer
242+
* @returns {void}
243+
*/
218244
function clearInterval(timer) {
219245
// clearTimeout and clearInterval can be used to clear timers created from
220246
// both setTimeout and setInterval, as specified by HTML Living Standard:
@@ -227,6 +253,10 @@ Timeout.prototype.close = function() {
227253
return this;
228254
};
229255

256+
/**
257+
* Coerces a `Timeout` to a primitive.
258+
* @returns {number}
259+
*/
230260
Timeout.prototype[SymbolToPrimitive] = function() {
231261
const id = this[async_id_symbol];
232262
if (!this[kHasPrimitive]) {
@@ -236,6 +266,15 @@ Timeout.prototype[SymbolToPrimitive] = function() {
236266
return id;
237267
};
238268

269+
/**
270+
* Schedules the immediate execution of `callback`
271+
* after I/O events' callbacks.
272+
* @param {Function} callback
273+
* @param {any} [arg1]
274+
* @param {any} [arg2]
275+
* @param {any} [arg3]
276+
* @returns {Immediate}
277+
*/
239278
function setImmediate(callback, arg1, arg2, arg3) {
240279
validateCallback(callback);
241280

@@ -271,7 +310,11 @@ ObjectDefineProperty(setImmediate, customPromisify, {
271310
}
272311
});
273312

274-
313+
/**
314+
* Cancels an immediate.
315+
* @param {Immediate} immediate
316+
* @returns {void}
317+
*/
275318
function clearImmediate(immediate) {
276319
if (!immediate || immediate._destroyed)
277320
return;

0 commit comments

Comments
 (0)