PollingEngine

Production-ready polling engine with exponential backoff and jitter.

  • Coroutine-friendly, supports cancellation.

  • Robust handling for rogue CancellationException (treat as retryable error if scope is still active).

  • Configurable via PollingConfig and BackoffPolicy.

  • Observability hooks and metrics (optional).

Types

Link copied to clipboard
data class Handle(val id: String)
Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard
suspend fun cancel(handle: PollingEngine.Handle)
suspend fun cancel(id: String)
Link copied to clipboard
suspend fun cancelAll()

Cancels all active polls and clears the registry.

Link copied to clipboard
suspend fun <T> compose(vararg configs: PollingConfig<T>): PollingOutcome<T>

Compose multiple polling operations sequentially. Stops early on non-success outcomes. Returns the last outcome (success from the last config or the first non-success).

Link copied to clipboard
suspend fun listActiveIds(): List<String>
Link copied to clipboard
suspend fun pause(id: String)
Link copied to clipboard
suspend fun <T> pollUntil(config: PollingConfig<T>): PollingOutcome<T>
Link copied to clipboard
suspend fun resume(id: String)
Link copied to clipboard
suspend fun shutdown()

Shuts down the engine: cancels all polls, cancels its scope, and prevents new polls from starting.

Link copied to clipboard
Link copied to clipboard
suspend fun updateBackoff(id: String, newPolicy: BackoffPolicy)