Skip to content

Commit 39c9f8e

Browse files
committed
commons/util: m jsdoc for timeout fn
1 parent b8f0627 commit 39c9f8e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/commons/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ export function timedSafeAsyncOp(promisedOp, ms, defaultOp) {
231231
}
232232

233233
/**
234-
*
234+
* Sets a timer which calls a function after ms milliseconds.
235+
* Max ms allowed is 2147483647 (~24 days), and min is 0.
235236
* @param {number} ms
236237
* @param {(...args: any[]) => void} fn
237238
* @returns
@@ -241,6 +242,7 @@ export function timeout(ms, fn) {
241242
// stackoverflow.com/a/62003170
242243
// max allowed timeout is ~24 days (int as ms)
243244
ms = ms > 2147483647 ? 2147483640 : ms;
245+
ms = ms < 0 ? 0 : ms;
244246
const timer = setTimeout(fn, ms);
245247
if (typeof timer.unref === "function") timer.unref();
246248
return timer;

0 commit comments

Comments
 (0)