UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

21 lines (20 loc) • 688 B
export async function withRetry(operation, options) { const { maxRetries, baseDelayMs, maxDelayMs = 30000, shouldRetry } = options; let lastError; for (let attempt = 0; attempt <= maxRetries; attempt++) { try { return await operation(); } catch (error) { lastError = error; if (shouldRetry && !shouldRetry(lastError)) { throw lastError; } if (attempt < maxRetries) { const delay = Math.min(baseDelayMs * 2 ** attempt, maxDelayMs); await new Promise((resolve) => setTimeout(resolve, delay)); } } } throw lastError; }