Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typings: add JSDoc typings for timers #38834

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,16 @@ function enroll(item, msecs) {
}


/*
* DOM-style timers
/**
* Schedules the execution of a one-time `callback`
* after `after` milliseconds.
* @param {Function} callback
* @param {number} [after]
* @param {any} [arg1]
* @param {any} [arg2]
* @param {any} [arg3]
* @returns {Timeout}
*/

function setTimeout(callback, after, arg1, arg2, arg3) {
validateCallback(callback);

Expand Down Expand Up @@ -170,6 +176,11 @@ ObjectDefineProperty(setTimeout, customPromisify, {
}
});

/**
* Cancels a timeout.
* @param {Timeout | string | number} timer
* @returns {void}
*/
function clearTimeout(timer) {
if (timer && timer._onTimeout) {
timer._onTimeout = null;
Expand All @@ -185,6 +196,16 @@ function clearTimeout(timer) {
}
}

/**
* Schedules repeated execution of `callback`
* every `repeat` milliseconds.
* @param {Function} callback
* @param {number} [repeat]
* @param {any} [arg1]
* @param {any} [arg2]
* @param {any} [arg3]
* @returns {Timeout}
*/
function setInterval(callback, repeat, arg1, arg2, arg3) {
validateCallback(callback);

Expand Down Expand Up @@ -215,6 +236,11 @@ function setInterval(callback, repeat, arg1, arg2, arg3) {
return timeout;
}

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

/**
* Coerces a `Timeout` to a primitive.
* @returns {number}
*/
Timeout.prototype[SymbolToPrimitive] = function() {
const id = this[async_id_symbol];
if (!this[kHasPrimitive]) {
Expand All @@ -236,6 +266,15 @@ Timeout.prototype[SymbolToPrimitive] = function() {
return id;
};

/**
* Schedules the immediate execution of `callback`
* after I/O events' callbacks.
* @param {Function} callback
* @param {any} [arg1]
* @param {any} [arg2]
* @param {any} [arg3]
* @returns {Immediate}
*/
function setImmediate(callback, arg1, arg2, arg3) {
validateCallback(callback);

Expand Down Expand Up @@ -271,7 +310,11 @@ ObjectDefineProperty(setImmediate, customPromisify, {
}
});


/**
* Cancels an immediate.
* @param {Immediate} immediate
* @returns {void}
*/
function clearImmediate(immediate) {
if (!immediate || immediate._destroyed)
return;
Expand Down