Function throttle

Throttles a function. Callback only allowed to run after minimum of intervalMinMs.

const moveThrottled = throttle( (elapsedMs, args) => {
// Handle ar
}, 500);
el.addEventListener(`pointermove`, moveThrottled)

Note that throttle does not schedule invocations, but rather acts as a filter that sometimes allows follow-through to callback, sometimes not. There is an expectation then that the return function from throttle is repeatedly called, such as the case for handling a stream of data/events.

// Set up once
const t = throttle( (elapsedMs, args) => { ... }, 5000);

// Later, trigger throttle. Sometimes the callback will run,
// with data passed in to args[0]
t(data);
  • Parameters

    • callback: ((elapsedMs: number, ...args: readonly unknown[]) => void | Promise<unknown>)
        • (elapsedMs, ...args): void | Promise<unknown>
        • Parameters

          • elapsedMs: number
          • Rest...args: readonly unknown[]

          Returns void | Promise<unknown>

    • intervalMinMs: number

    Returns ((...args: unknown[]) => Promise<void>)

      • (...args): Promise<void>
      • Parameters

        • Rest...args: unknown[]

        Returns Promise<void>