RetryAsyncContextImpl

internal class RetryAsyncContextImpl(val config: RetryConfig, val eventFlow: MutableSharedFlow<RetryEvent>) : RetryAsyncContext(source)

Represents the asynchronous context implementation of a retry mechanism. Besides defining context behaviour, this implementation is also responsible for:

  • state management;

  • event emission.

For each retryable asynchronous operation, a new instance of this class must be created.

Parameters

config

The configuration for the retry mechanism.

eventFlow

The shared flow to emit retry events to.

See also

Constructors

Link copied to clipboard
constructor(config: RetryConfig, eventFlow: MutableSharedFlow<RetryEvent>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
private val config: RetryConfig
Link copied to clipboard
Link copied to clipboard
private val eventFlow: MutableSharedFlow<RetryEvent>
Link copied to clipboard
private val isRetryAttempt: Boolean
Link copied to clipboard
private var lastThrowable: Throwable?

Functions

Link copied to clipboard
open suspend override fun onError(throwable: Throwable): Boolean

Handles an error that occurred during the asynchronous operation execution. Such handling may include deciding whether to retry the operation or ignore the error and complete the operation. This method might propagate the error if retrying is no longer possible (e.g., the maximum number of attempts was reached), and the caller did not specify a custom error handler.

Link copied to clipboard
open suspend override fun onResult(result: Any?): Boolean

Determines whether a retry should be attempted based on the result of the asynchronous operation.

Link copied to clipboard
open suspend override fun onRetry()

Initiates a retry attempt by applying the delay strategy.

Link copied to clipboard
open suspend override fun onSuccess()

Handles the successful completion of the asynchronous operation. Even if the operation is completed without retrying once, this method is still called.

Link copied to clipboard
private fun shouldRetry(throwable: Throwable): Boolean
Link copied to clipboard
private fun shouldRetryOnResult(result: Any?): Boolean