es-toolkit
es-toolkit copied to clipboard
retry function retries one time less than specified
in the retry function there is a retries option, but it is actually the number of attempts, not retries.
for example this code
import { delay, retry } from 'es-toolkit';
let request = 0;
async function f() {
console.log("request", request++);
await delay(10)
throw Error("err!")
}
await retry(f, 1);
outputs
request 0
Error: err!
so it only does one request, zero retries instead of one.
the problem is this line in retry
for (let attempts = 0; attempts < retries; attempts++) {
should be
for (let attempts = 0; attempts <= retries; attempts++) {
then the function also works when calling it with 0 retries (which currently does not work)