TracedDispatcherProvider

A DispatcherProvider whose main, io and default dispatchers are TracingDispatchers reporting to sink, created by traced. unconfined is returned unwrapped: tracing it is pointless (it never queues) and would leave dangling TraceEvent.Queued events on yield().

Wrapping is lazy: Dispatchers.Main is not touched until main is read.

Example:

val dispatchers = DefaultDispatcherProvider.traced(RingBufferSink(256))
withContext(dispatchers.io) { api.fetch() }
dispatchers.sink // the sink that received the events

Requires opting in to ExperimentalStructuredCoroutines. Not constructed directly; use traced.

See also

Properties

Link copied to clipboard
open override val default: CoroutineDispatcher

Dispatcher for CPU-bound work.

Link copied to clipboard
open override val io: CoroutineDispatcher

Dispatcher for blocking IO. The default implementation resolves it through ioCompat.

Link copied to clipboard
open override val main: CoroutineDispatcher

UI dispatcher. May be unavailable on platforms without a main dispatcher (for example a plain JVM process without a UI toolkit); in that case accessing it fails the way Dispatchers.Main does.

Link copied to clipboard

The sink that receives the events of the wrapped dispatchers.

Link copied to clipboard
open override val unconfined: CoroutineDispatcher

Unconfined dispatcher. Runs in the caller thread until the first suspension; avoid for work that needs thread affinity.

Functions

Link copied to clipboard

Wraps this provider's main, io and default dispatchers in InstrumentedDispatchers with those labels; unconfined is returned as is (see InstrumentedDispatcherProvider). Wrapping is lazy: nothing (including Dispatchers.Main) is read until the corresponding property is accessed.

Link copied to clipboard

The maximum concurrency of the traced dispatcher label, or null when unknown. Meant to feed PoolSampler's parallelism argument.

Link copied to clipboard

Wraps this provider's main, io and default dispatchers in TracingDispatchers labeled "main", "io" and "default" that report to sink. unconfined is returned as is.