@nevware21/ts-utils
    Preparing search index...

    Function 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.

      Parameters

      • OptionaloverrideFn: TimeoutOverrideFn | TimeoutOverrideFuncs

        setTimeout 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

      Returns void

      0.12.3

      The global timeout overrides serve as a fallback when no specific or package level overrides are provided. The priority order for timeout functions is:

      1. Specific override provided to the individual function call for scheduleTimeoutWith or createTimeoutWith
      2. Package instance overrides set via setTimeoutOverrides
      3. Global overrides set via this function
      4. Native setTimeout/clearTimeout functions
      // 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();