• Delays the invocation of a Callback function.

    Example

    Call callback after 500ms

    const callback = (val) => console.log(val);
    delay(callback, 500, "val");

    // prints "val" after 500ms

    Example

    Cancel delay

    const callback = (val) => console.log(val);
    const cancelDelay = delay(callback, 500, "val");
    cancelDelay();

    // will not call the callback

    Returns

    the cancel Callback function

    Type Parameters

    • TArgs extends unknown[] = []

    Parameters

    • callback: Callback<TArgs>

      the Callback to call

    • ms: number

      the number of milliseconds to delay the function call

    • Rest ...args: TArgs

      the arguments to pass to the callback function

    Returns CancelCallback

Generated using TypeDoc