DispatcherBulkhead

Isolation-by-dispatcher bulkhead: like Bulkhead, but every admitted call runs on a dedicated CoroutineDispatcher instead of the caller's context.

A semaphore-only Bulkhead bounds concurrency but a slow/blocking call still occupies the caller's threads. Running the protected work on its own dispatcher (e.g. a fixed thread pool, see ThreadPoolBulkhead on the JVM) keeps a slow dependency from starving the rest of the application.

val bulkhead = DispatcherBulkhead.create(Dispatchers.IO.limitedParallelism(4))
bulkhead.execute { blockingCall() }

Types

Link copied to clipboard
object Companion

Factory for DispatcherBulkhead.

Properties

Link copied to clipboard

The configuration of the underlying permit/queue bulkhead.

Link copied to clipboard

Dispatcher on which admitted calls run.

Functions

Link copied to clipboard
suspend fun activeCalls(): Int

Returns the current number of active calls.

Link copied to clipboard

Adds a listener for bulkhead events.

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

Executes block on dispatcher once a permit is available.

Link copied to clipboard
suspend fun <T> executeOrFallback(fallback: suspend () -> T, block: suspend () -> T): T

Like execute but runs fallback when rejected.

Link copied to clipboard
suspend fun resetStatistics()

Resets all statistics counters.

Link copied to clipboard

Returns a snapshot of the current statistics.

Link copied to clipboard
suspend fun <T> tryExecute(block: suspend () -> T): T?

Like execute but returns null when rejected.

Inherited functions

Link copied to clipboard