Reference / @open-music-sdk/core / retry
Function: retry()
function retry<T>(
fn,
policy?,
signal?
): Promise<T>;Defined in: packages/core/src/retry.ts:85
Runs fn until it resolves or the policy gives up. Waits with full jitter, or for Retry-After when the error carries one and it is within maxRetryAfterMs; a longer Retry-After ends the retrying immediately.
Only an AppleMusicError that retryOn accepts is tried again; anything else fn rejects with ends the retrying there and then. The attempts are numbered from 1, and fn is told which it is on.
Type Parameters
T
T
Parameters
fn
(attempt) => Promise<T>
One attempt, given its number; what it resolves to is the answer.
policy?
How many attempts and how long between them; each field left out is the default.
signal?
AbortSignal
Ends the retrying: no attempt is begun and no wait goes on once it has fired.
Returns
Promise<T>
What the first attempt to succeed resolved to.
Throws
TypeError if a field of policy is not what tRetryPolicy says, or signal is no AbortSignal.
Throws
Whatever the last attempt rejected with, as it is, when it is no AppleMusicError, retryOn turns it down, its retryAfterMs is beyond maxRetryAfterMs, or the attempts are used up; and whatever retryOn itself throws.
Throws
The reason signal aborted with, when it does.