limiter
Version:
A generic rate limiter for the web and node.js. Useful for API clients, web crawling, or other tasks that need to be throttled
10 lines • 459 B
JavaScript
// performance.now() is monotonic in both Node.js and browsers.
export function getMilliseconds() {
return performance.now();
}
// Clamp long waits: runtimes turn delays above 2^31 - 1 into near-zero timers.
// Callers recheck availability after waking, including after a capped wait.
export function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, Math.min(2147483647, Math.max(1, Math.ceil(ms)))));
}
//# sourceMappingURL=clock.js.map