@metreeca/core - v0.9.11
    Preparing search index...

    Function Throttle

    • Creates an adaptive throttle for rate-limiting concurrent task execution.

      The throttle combines two independent delay mechanisms:

      • Queue-based scaling (buildup): Increases delays exponentially based on concurrent task count (effective_delay = delay × buildup^queue). This prevents overload when many tasks queue up.
      • Adaptive adjustment (backoff/recover): Modifies the baseline delay based on task outcomes. Failures trigger backoff (delay × backoff), successes trigger recovery (delay × recover).

      These mechanisms work together: buildup provides immediate load-based throttling, while backoff/recover adapt the baseline rate based on system feedback over time.

      Parameters

      • options: {
            minimum?: number;
            maximum?: number;
            buildup?: number;
            backoff?: number;
            recover?: number;
        } = {}

        Configuration options for the throttle

        • Optionalminimum?: number

          The minimum delay between task executions in milliseconds; must be non-negative

        • Optionalmaximum?: number

          The maximum delay between task executions in milliseconds; 0 means no limit

        • Optionalbuildup?: number

          The exponential factor for queue-based delay increases; must be >= 1.0

        • Optionalbackoff?: number

          The multiplicative factor for increasing delays on task failure; must be >= 1.0

        • Optionalrecover?: number

          The multiplicative factor for decreasing delays on task success; must be 0.0-1.0

      Returns Throttle

      A throttle instance for rate-limiting operations

      const throttle = Throttle({ minimum: 100, backoff: 2.0, recover: 0.5 });

      await throttle.queue(true);

      try {
      await processItem();
      await throttle.adapt(true);
      } catch (error) {
      await throttle.adapt(false);
      }

      Error if any parameter validation fails