PollingConfigBuilder

Builder Pattern for creating PollingConfig in a fluent, readable way. Keeps compatibility by producing the existing PollingConfig.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

Sets the backoff policy controlling delays, jitter, attempts, and timeouts.

Link copied to clipboard
Link copied to clipboard
fun dispatcher(dispatcher: CoroutineDispatcher): PollingConfigBuilder<T>

Sets the CoroutineDispatcher used to run polling. Defaults to Dispatchers.Default.

Link copied to clipboard
fun fetch(block: suspend () -> PollingResult<T>): PollingConfigBuilder<T>

Sets the suspending fetch operation that produces a PollingResult per attempt. Typical implementation performs I/O and maps responses/errors to domain results.

Link copied to clipboard
fun onAttempt(hook: (attempt: Int, delayMs: Long?) -> Unit): PollingConfigBuilder<T>

Hook invoked before each attempt is executed, providing the attempt index and the computed delay for the upcoming attempt (null for immediate).

Link copied to clipboard
fun onComplete(hook: (attempts: Int, durationMs: Long, outcome: PollingOutcome<T>) -> Unit): PollingConfigBuilder<T>

Hook invoked once with the terminal outcome, total attempts, and elapsed time.

Link copied to clipboard
fun onResult(hook: (attempt: Int, result: PollingResult<T>) -> Unit): PollingConfigBuilder<T>

Hook invoked after each attempt completes with a result (Success/Waiting/Failure/Unknown/Cancelled).

Link copied to clipboard
fun retry(predicate: (Error?) -> Boolean): PollingConfigBuilder<T>

Sets the retry predicate used when the last attempt produced a Failure(Error). Return true to retry, false to stop with Exhausted. See built-ins in RetryPredicates.

Link copied to clipboard
fun success(predicate: (T) -> Boolean): PollingConfigBuilder<T>

Sets the terminal success predicate. When it returns true for a Success(value), polling stops with PollingOutcome.Success.

Link copied to clipboard

Sets a mapper to convert thrown exceptions into domain Error values. Defaults to a mapper that uses code=-1 and Throwable.message/class name.