zeed
    Preparing search index...

    Function throttle

    • A special throttle implementation that tries to distribute execution in an optimal way.

      Functionality: For UI usage the function is executed on first occasion (leading). If more calls follow it will again be executed at end (trailing). If the next call is inside the timeframe, it is delayed until trailing. This avoids timewise too close calls. It is possible to cancel the timeout and to flush a call, e.g. if leaving UI situation where a final call is required to write data or similar.

      Type Parameters

      • F extends (...args: any[]) => any

      Parameters

      • callback: F
      • opt: { delay?: number; leading?: boolean; trailing?: boolean } = {}

      Returns F & {
          cancel: () => void;
          dispose: () => void;
          immediate: (...args: Parameters<F>) => Promise<void>;
          stop: () => void;
      }

      • cancel: () => void

        Stop all timers, do not exec nothing

      • dispose: () => void
      • immediate: (...args: Parameters<F>) => Promise<void>

        Stop all timers and execute right now.

      • stop: () => void

        Stop all timers and execute trailing call, if exists.