Unique label for telemetry (e.g., "GET /api/items")
Function returning a Promise
Optional
cfg: RetryConfigRetryConfig
The resolved value from the operation, or throws after all retries fail.
// Retry GET request up to 5 times, with exponential backoff starting at 300ms
const data = await retry("GET /api/patients", async () => {
const res = await fetch("/api/patients");
if (!res.ok) throw new Error(`Status ${res.status}`);
return res.json();
}, {
retries: 5,
baseMs: 300,
jitter: true,
report: true // enable DataDog telemetry at default 10% sampling
});
Retry an async operation with backoff/jitter.