@tremendous/help
    Preparing search index...

    Function sampler

    • Executes a given function approximately once every count calls.

      This function uses a random number generator to determine if the provided function should be executed. On average, the function will be executed once every count calls.

      Type Parameters

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

        The type of the function to be executed.

      Parameters

      • fn: T

        The function to be executed.

      • count: number

        The approximate number of calls after which the function should be executed once.

      Returns void

      const logMessage = () => console.log("Function executed");
      sampler(logMessage, 10); // logMessage will be executed approximately once every 10 calls