melonJS
    Preparing search index...

    Function defer

    • Executes a function as soon as the interpreter is idle (stack empty).

      Generic over the target function's tail-args tuple so call sites pass the function's actual parameters without lying to TypeScript via as unknown as (...args: unknown[]) => unknown casts. The compiler infers TArgs from the trailing rest args and constrains func to accept them.

      Type Parameters

      • TArgs extends unknown[]

      Parameters

      • func: (...args: TArgs) => unknown

        The function to be deferred.

      • thisArg: unknown

        The value to be passed as the this parameter to the target function when the deferred function is called

      • ...args: TArgs

        Optional additional arguments to carry for the function.

      Returns number

      id that can be used to clear the deferred function using clearTimeout

      // execute myFunc() when the stack is empty,
      // with the current context and [1, 2, 3] as parameter
      me.utils.function.defer(myFunc, this, 1, 2, 3);