Tweakr
    Preparing search index...

    Function after

    • Creates a function that invokes fn only after it has been called n times.

      The returned function will call fn after the specified number of invocations. Until then, it returns undefined. After the first successful call, the result of fn is cached and returned on subsequent calls.

      Type Parameters

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

        The type of the function to be invoked.

      Parameters

      • n: number

        The number of calls required before invoking fn.

      • fn: T

        The function to invoke after n calls.

      Returns (...args: Parameters<T>) => undefined | ReturnType<T>

      A new function that waits for n calls.

      1.2.0

      const ready = after(3, () => console.log("Ready!"));
      ready(); ready(); ready(); // logs "Ready!"