Matterway
    Preparing search index...

    Function createDelayedPLimit

    • Creates a concurrency-limited queue with a fixed delay between the start times of tasks.

      Parameters

      • concurrency: number = 1

        How many tasks can run simultaneously

      • delayMs: number = 100

        Milliseconds to wait after one task starts before the next starts

      Returns <T>(fn: () => Promise<T>) => Promise<T>

      A function that accepts a task (a function returning a Promise) and returns a Promise of its result.

      Example usage:

      const limit = createDelayedPLimit(2, 100); // concurrency=2, delay=100ms

      async function doAsync(label: string) {
      console.log(`Starting: ${label}`);
      await new Promise((r) => setTimeout(r, 500));
      console.log(`Finished: ${label}`);
      return label;
      }

      // Queue some tasks
      const tasks = ['A', 'B', 'C', 'D'].map(
      (label) => limit(() => doAsync(label)),
      );

      // Wait for all
      const results = await Promise.all(tasks);
      console.log(results); // ['A', 'B', 'C', 'D']
        • <T>(fn: () => Promise<T>): Promise<T>
        • The function returned by createDelayedPLimit. It schedules a new task (fn) under concurrency + delay constraints, returning a Promise of fn()'s result.

          Type Parameters

          • T

          Parameters

          • fn: () => Promise<T>

          Returns Promise<T>