Skip to main content
cngx-src documentation

withRetry

Functioncommon/interactive/retry

projects/common/interactive/retry/with-retry.ts

Description#

Wraps an AsyncAction with automatic retry logic.

Returns a tuple: [action, retryState] where action is a new AsyncAction that retries on failure, and retryState exposes attempt/retry signals and a state: CngxAsyncState for feedback system integration.

Composes naturally with CngxAsyncClick and CngxActionButton:

const [saveWithRetry, retryState] = withRetry(
  () => this.http.post('/api/save', data),
  { maxAttempts: 3, delay: 1000, backoff: 'exponential' }
);

// Use with CngxAsyncClick + toast
<button [cngxAsyncClick]="saveWithRetry">Save</button>
<ng-container [cngxToastOn]="retryState.state"
  toastSuccess="Saved" toastError="All retries failed" />

Signature#

withRetry(action: AsyncAction, config?: RetryConfig)

Parameters#

@paramactionAsyncAction
@paramconfig?RetryConfig

Returns#

unknown