Optional
overrideFn: TimeoutOverrideFn | TimeoutOverrideFuncssetTimeout override function this will be called instead of the setTimeout
, if the value
of overrideFn
is null or undefined it will reset the global overrides to undefined.
May also be an array with both the setTimeout and clearTimeout override functions, if either is not provided the
default native functions will be used
The global timeout overrides serve as a fallback when no specific or package level overrides are provided. The priority order for timeout functions is:
// Override with global custom setTimeout and clearTimeout implementations
function customSetTimeout<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs) {
console.log(`Global: Setting timeout for ${ms}ms`);
return setTimeout(callback, ms);
}
function customClearTimeout(timeoutId: number) {
console.log(`Global: Clearing timeout ${timeoutId}`);
return clearTimeout(timeoutId);
}
// Set global override functions
setGlobalTimeoutOverrides([customSetTimeout, customClearTimeout]);
// Now all timeout operations will use these global implementations when no other overrides are provided
let timer = scheduleTimeout(() => {
console.log("Timer triggered");
}, 100);
// Reset global overrides
setGlobalTimeoutOverrides();
Sets global timeout override functions that will be used as fallback by all timeout operations when no specific or default package override functions are provided. If called with no parameters or undefined, it will reset the global overrides to undefined.