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

    Type Alias CancelIdleCallback

    CancelIdleCallback: (handle: number) => void

    Type alias for the global cancelIdleCallback function, which cancels a previously scheduled idle callback. Using a type alias makes it easier to reference and annotate the function, and supports older TypeScript versions that may not include the global declaration.

    When using scheduleIdleCallback you can cancel the scheduled work through the returned ITimerHandler instead of calling cancelIdleCallback directly. Use this type (via getCancelIdleCallback) only when you need the raw browser API.

    Type Declaration

      • (handle: number): void
      • Parameters

        • handle: number

          The handle returned by requestIdleCallback that identifies the idle callback to cancel. Passing an invalid or already-consumed handle is a no-op.

        Returns void

    0.11.2

    // Schedule then immediately cancel an idle callback
    const reqIdle = getIdleCallback();
    const cancelIdle: CancelIdleCallback | null = getCancelIdleCallback();

    if (reqIdle && cancelIdle) {
    const handle = reqIdle((deadline) => {
    // background work
    });

    // cancel before the callback fires
    cancelIdle(handle);
    }
    // Store a typed reference for later use
    let _cancelIdle: CancelIdleCallback | null = null;

    function ensureCancelIdle(): CancelIdleCallback | null {
    return _cancelIdle || (_cancelIdle = getCancelIdleCallback());
    }