pols-utils - v5.3.11
    Preparing search index...

    Function debounce

    • Creates a debounced version of the given function. The returned function delays the execution of func until after a specified delay time has passed since the last time it was called. If the returned function is called again before the delay has expired, the previous call is canceled and the timer resets.

      Parameters

      • func: (...args: unknown[]) => void

        The function to debounce.

      • delay: number

        The delay time in milliseconds.

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

      A debounced version of func that executes only after the delay time has passed without further calls.

      let count = 1
      const myfunc = () => {
      console.log('Call ' + count)
      count++
      }
      const myfuncDebounce = PUtilsFunction.debounce(myfunc, 1000)

      // First context
      myfuncDebounce() // Execute myfunc after 1 second: 'Call 1'

      // Another context
      myfuncDebounce() // Call 1 (canceled)
      myfuncDebounce() // Reset time. It cancel the called one and after 1 seconde: 'Call 2'