Policy

interface Policy(source)

A composable resilience decorator: applies some cross-cutting behavior (retry, circuit breaking, rate limiting, ...) around a suspend operation.

Any of Bulkhead, CircuitBreaker, RateLimiter, TimeLimiter can be converted to a Policy via their asPolicy() extension, and policies compose with plus.

Implemented as a plain interface (not a fun interface): apply is generic per call, which a stored lambda cannot represent, so instances are created via the factory functions in this file rather than SAM conversion.

Types

Link copied to clipboard
object Companion

Factory helpers for combining multiple Policy instances.

Functions

Link copied to clipboard
abstract suspend fun <T> apply(block: suspend () -> T): T

Runs block through this policy's protective behavior.

Inherited functions

Link copied to clipboard
operator fun Policy.plus(other: Policy): Policy

Composes two policies so that this wraps other: (a + b).apply(block) runs as a.apply { b.apply(block) }.