Skip to content

Feature Request - awaitNextInterval #205

@jaysteiner-dev

Description

@jaysteiner-dev

I'm using the p-queue for throttling, where potentially the API I am trying to hit could still rate limit me.
It would be great if there was a function I could use to handle those timeout after I catch the errors.

const queue = new PQueue({
    concurrency: 50,
    interval: 10000,
    intervalCap: 1000
    carryoverConcurrencyCount: true
});

const promises = myObjects.map(
  (obj) => async () =>
    myApiCall(obj.id).catch((err) => {
      if (err.code === HttpStatus.TOO_MANY_REQUESTS) {
        queue.awaitNextInterval()
      }
      this.logger.error(`failed with:`, err);
    })
);

await queue.addAll(promises);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions