Function SetTimeout

  • Runs the given callback after duration seconds. Returns a cancellation function.

    Note: This is functionally equivalent to task.delay, except a cancellation function is returned rather than the created thread.

    Type Parameters

    • T extends unknown[]

    Parameters

    • duration: number

      Seconds to wait before calling the callback function.

    • callback: ((...args) => void)

      The function to call.

        • (...args): void
        • Parameters

          • Rest ...args: T

          Returns void

    • Rest ...args: T

      Optional arguments to pass to the callback function.

    Returns (() => void)

    Cancellation function.

    const cancel = SetTimeout(1, () => {
    print("This code runs after 1 second");
    });

    // Optionally stop the timeout from running:
    cancel();
      • (): void
      • Returns void