Skip to content

Add retryOperation.nextTimeout() - #100

Open
tim-kos wants to merge 2 commits into
masterfrom
next-timeout
Open

tim-kos wants to merge 2 commits into
masterfrom
next-timeout

Conversation

@tim-kos

@tim-kos tim-kos commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Callers want to log how long the operation waits before the next attempt, e.g. pnpm's "Will retry in 16 seconds" (#73). Until now the only way to find out was to read operation._timeouts[0], and that is wrong in forever mode.

This adds retryOperation.nextTimeout(). It returns the delay, in milliseconds, of the retry that the last retry() call scheduled, and null when that call scheduled nothing. It is also null before any retry, and after reset() or stop(). retry() keeps returning a boolean, so existing if (operation.retry(err)) code is unaffected.

if (operation.retry(err)) {
  console.warn('Request failed, retrying in ' + operation.nextTimeout() + 'ms');
  return;
}

Call it right after retry(). Inside the next attempt it still returns the timeout that led up to that attempt, and the README says so.

Once forever used up its timeouts, it used to wrap the last one in a one-element array. This PR makes it a number, so nextTimeout() returns a number in that case too. #99 makes the identical one-line change. #97–#100 merge together in either order with all tests passing.

Fixes #73

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n to call it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

It would be useful if the retry function returned the timout number

1 participant