Skip to content

Commit

Permalink
timers: document ref option for scheduler.wait
Browse files Browse the repository at this point in the history
PR-URL: #54605
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
  • Loading branch information
ShogunPanda authored and aduh95 committed Sep 12, 2024
1 parent 2a1f56c commit b3d567a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 3 additions & 0 deletions doc/api/timers.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ added:
* `delay` {number} The number of milliseconds to wait before resolving the
promise.
* `options` {Object}
* `ref` {boolean} Set to `false` to indicate that the scheduled `Timeout`
should not require the Node.js event loop to remain active.
**Default:** `true`.
* `signal` {AbortSignal} An optional `AbortSignal` that can be used to
cancel waiting.
* Returns: {Promise}
Expand Down
22 changes: 9 additions & 13 deletions lib/timers/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,18 @@ function setImmediate(value, options = kEmptyObject) {
}

async function* setInterval(after, value, options = kEmptyObject) {
try {
if (typeof after !== 'undefined') {
validateNumber(after, 'delay');
}
if (typeof after !== 'undefined') {
validateNumber(after, 'delay');
}

validateObject(options, 'options');
validateObject(options, 'options');

if (typeof options?.signal !== 'undefined') {
validateAbortSignal(options.signal, 'options.signal');
}
if (typeof options?.signal !== 'undefined') {
validateAbortSignal(options.signal, 'options.signal');
}

if (typeof options?.ref !== 'undefined') {
validateBoolean(options.ref, 'options.ref');
}
} catch (err) {
return PromiseReject(err);
if (typeof options?.ref !== 'undefined') {
validateBoolean(options.ref, 'options.ref');
}

const { signal, ref = true } = options;
Expand Down

0 comments on commit b3d567a

Please sign in to comment.