# utils/retry

module

<a id="functions">

## Functions

<a id="function-exponentialDelay">

### `exponentialDelay( options = { options.delay?, options.factor?, options.maxDelay? } ) → ( attempt: number ) => number`

Creates a function that calculates exponential back-off delay. Pass it as `options.retryDelay` to [`retry`](#function-retry).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/retry.ts#L63)

#### Parameters

* `options: object`

  Properties

  * `options.delay?: number`

    Base delay between invocations. Defaults to 1s.

  * `options.factor?: number`

    How much to increase the delay. Defaults to 2x.

  * `options.maxDelay?: number`

    Maximum timeout. Even if higher timeout is calculated, it cannot get higher than this value. Default to 10s.

  Defaults to `{}`

#### Returns

* `( attempt: number ) => number`

  The function calculating the delay.

<a id="function-retry">

### `retry( callback, options = { options.maxAttempts?, options.retryDelay?, options.signal? } ) → Promise<TResult>`

Tries calling the given callback until it sucessfully resolves.

If the callback fails `maxAttempts` times, the returned promise is rejected with the last error.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/retry.ts#L24)

#### Type parameters

* `TResult`

  The result of a successful callback invocation.

#### Parameters

* `callback: () => Promise<TResult>`

  The function to call until it succeeds.

* `options: object`

  Configuration options.

  Properties

  * `options.maxAttempts?: number`

    Maximum number of attempts.

  * `options.retryDelay?: ( attempt: number ) => number`

    The time in milliseconds between attempts. By default it implements exponential back-off policy.

  * `options.signal?: AbortSignal`

    The signal to abort further retries. The callback itself is not aborted automatically.

  Defaults to `{}`

#### Returns

* `Promise<TResult>`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
