@hyperfrontend/immutable-api-utils/built-in-copy/timerstimers
Locked, prototype-pollution-resistant copies of the global timer and scheduling functions.
setTimeout, setInterval, clearTimeout, clearInterval, queueMicrotask, and (where available) requestAnimationFrame / cancelAnimationFrame are captured at module-load time and frozen into a tamper-proof namespace, so scheduled work keeps firing on real host timers even if the globals are later patched. Effective only when imported before any untrusted code has had a chance to mutate the prototype chain.
API Reference
ƒ Functions
(Safe copy) Cancels a timed, repeating action previously established by setInterval.
Parameters
| Name | Type | Description |
|---|---|---|
§id | Timeout | The identifier of the interval to cancel. |
Example
Canceling an interval
const intervalId = setInterval(() => console.log('tick'), 1000)
// Stop after some condition
clearInterval(intervalId)(Safe copy) Cancels a timeout previously established by setTimeout.
Parameters
| Name | Type | Description |
|---|---|---|
§id | Timeout | The identifier of the timeout to cancel. |
Example
Canceling a timeout
const timerId = setTimeout(() => console.log('Never runs'), 5000)
clearTimeout(timerId)(Safe copy) Queues a microtask to be executed before control returns to the event loop.
Parameters
| Name | Type | Description |
|---|---|---|
§callback | VoidFunction | Function to execute. |
Example
Queuing a microtask
console.log('Start')
queueMicrotask(() => console.log('Microtask'))
console.log('End')
// Output: Start, End, Microtask§function
setInterval<TArgs>(callback: (args: TArgs) => void, delay?: number, ...args: TArgs): Timeout
(Safe copy) Repeatedly calls a function with a fixed time delay between each call.
Parameters
Returns
TimeoutA numeric ID for the interval.
Example
Setting an interval
let count = 0
const intervalId = setInterval(() => {
count++
if (count >= 5) clearInterval(intervalId)
}, 1000)§function
setTimeout<TArgs>(callback: (args: TArgs) => void, delay?: number, ...args: TArgs): Timeout
(Safe copy) Sets a timer which executes a function once the timer expires.
Parameters
Returns
TimeoutA numeric ID for the timer.
Example
Setting a timeout
const timerId = setTimeout(() => console.log('Executed'), 1000)
// Pass arguments to callback
setTimeout((name, count) => console.log(name, count), 500, 'items', 5)● Variables
(Safe copy) Cancels an animation frame request previously scheduled. Available only in browser environments.
(Safe copy) Requests the browser to call a function before the next repaint. Available only in browser environments.
(Safe copy) Namespace object containing all Timer/Scheduling functions. Note: Importing this imports all methods in this namespace (no tree-shaking).