Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - awaitNextInterval #205

Open
jaysteiner-dev opened this issue Apr 12, 2024 · 1 comment
Open

Feature Request - awaitNextInterval #205

jaysteiner-dev opened this issue Apr 12, 2024 · 1 comment

Comments

@jaysteiner-dev
Copy link

jaysteiner-dev commented Apr 12, 2024

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);
@sindresorhus
Copy link
Owner

What exactly would queue.awaitNextInterval() do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants