Package-level declarations
Public API of the runtime toolkit.
Helpers that run inside an existing coroutine respect structured concurrency: they never launch into a scope the caller does not own, they let CancellationException propagate, and anything they start finishes before they return. Diagnostic types (tracing, metrics, signals) are opt-in and have no effect unless they are wired in explicitly.
Public API of the runtime toolkit.
Helpers that run inside an existing coroutine respect structured concurrency: they never launch into a scope the caller does not own, they let CancellationException propagate, and anything they start finishes before they return. Diagnostic types (tracing, metrics, signals) are opt-in and have no effect unless they are wired in explicitly.
Public API of the runtime toolkit.
Helpers that run inside an existing coroutine respect structured concurrency: they never launch into a scope the caller does not own, they let CancellationException propagate, and anything they start finishes before they return. Diagnostic types (tracing, metrics, signals) are opt-in and have no effect unless they are wired in explicitly.
Public API of the runtime toolkit.
Helpers that run inside an existing coroutine respect structured concurrency: they never launch into a scope the caller does not own, they let CancellationException propagate, and anything they start finishes before they return. Diagnostic types (tracing, metrics, signals) are opt-in and have no effect unless they are wired in explicitly.
Public API of the runtime toolkit.
Helpers that run inside an existing coroutine respect structured concurrency: they never launch into a scope the caller does not own, they let CancellationException propagate, and anything they start finishes before they return. Diagnostic types (tracing, metrics, signals) are opt-in and have no effect unless they are wired in explicitly.
Public API of the runtime toolkit.
Helpers that run inside an existing coroutine respect structured concurrency: they never launch into a scope the caller does not own, they let CancellationException propagate, and anything they start finishes before they return. Diagnostic types (tracing, metrics, signals) are opt-in and have no effect unless they are wired in explicitly.
Public API of the runtime toolkit.
Helpers that run inside an existing coroutine respect structured concurrency: they never launch into a scope the caller does not own, they let CancellationException propagate, and anything they start finishes before they return. Diagnostic types (tracing, metrics, signals) are opt-in and have no effect unless they are wired in explicitly.
Public API of the runtime toolkit.
Helpers that run inside an existing coroutine respect structured concurrency: they never launch into a scope the caller does not own, they let CancellationException propagate, and anything they start finishes before they return. Diagnostic types (tracing, metrics, signals) are opt-in and have no effect unless they are wired in explicitly.
Types
A TraceSink that writes dispatch activity to the Android system trace (android.os.Trace), so it shows up in Perfetto, Android Studio's system trace and Macrobenchmark TraceSectionMetric.
Fans every event out to several sinks. Enabled for a level when any sink is. Each sink is called in isolation: an Exception from one does not stop the others (VM errors propagate). Only sinks enabled for the event's level receive it.
Production DispatcherProvider backed by the real Dispatchers.
Immutable snapshot of what a StatsSink observed for one dispatcher label. A plain final class with explicit equals/hashCode/toString so fields can be added later without breaking binary compatibility.
Abstraction over the four standard dispatchers, meant to be injected into classes instead of hardcoding Dispatchers.* so tests can swap in a test dispatcher with virtual time.
Immutable snapshot of what an InstrumentedDispatcher observed.
One-shot events (navigation, snackbars) that must not be lost when nobody is collecting yet and must be handled once. Backed by a Channel with a buffer, per FLOW_011 (a default MutableSharedFlow with replay = 0 drops events emitted before a collector attaches).
Marks declarations in the :runtime optional companion library that are still experimental.
Immutable view of a latency distribution captured from a histogram.
A CoroutineDispatcher that wraps delegate and records how many blocks were dispatched, how many ran concurrently at peak, and the longest queue delay (dispatch to block start). Useful to detect saturated dispatchers while diagnosing slow or starved coroutines.
A DispatcherProvider whose main, io and default dispatchers are InstrumentedDispatchers, created by instrumented. unconfined is returned unwrapped: it never queues work, so its counters would always read zero, and yield() on a wrapped one would count a dispatch that never starts.
Writes each event as one human-readable line (its toString) to log. Never throws: an Exception from log is swallowed so logging cannot break dispatch.
Periodically turns the cumulative state of a StatsSink into TraceEvent.PoolSamples so a pool can be watched over time. One sample is emitted per dispatcher label that stats knows.
A heuristic hint derived from DispatcherMetrics. Sealed so more signals can be added later. Signals are hints, not proof: they say where to look, not what is wrong.
Keeps the last capacity events, for tests, crash reports and ad-hoc export.
Thresholds used by signals to turn DispatcherMetrics into PoolSignals. Plain final class with explicit equals/hashCode/toString so options can be added later.
Holds a piece of UI/domain state and exposes it read-only, implementing the FLOW_010 backing property pattern: the MutableStateFlow is private, so external code can only change state through set and update.
A TraceSink that aggregates events into per-dispatcher DispatcherMetrics: counters, running and peak concurrency, queue-delay and run-time histograms, failures and distinct threads.
Identity of a platform thread. A plain final class (not a data class) so fields can be added later without a binary-incompatible copy/componentN change.
What the current target can do for tracing out of the box, as shipped in :runtime. This is the extension seam for new platforms: a target compiles and works with every flag false, and gains fidelity when someone writes its actual of platformCapabilities and platformTraceSink.
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().
An observation emitted to a TraceSink. Sealed so subtypes can be added later; sinks must ignore subtypes they do not know.
How much detail a TraceSink wants to receive. Levels are cumulative by ordinal: enabling a level also enables every level below it, so level <= maxLevel is the enablement test.
How a traced block ended.
Port that receives TraceEvents. Backends (logging, ring buffers, platform tracers) implement it.
A unit of traced work, carried in the coroutine context. TracingDispatcher reads it from the context of every dispatch and attaches id, parentId and name to the run events, so a backend can draw parent-child links and show the span label.
A CoroutineDispatcher that wraps delegate and emits a TraceEvent.Queued, TraceEvent.Started and TraceEvent.Finished event to sink for every block dispatched through it. label identifies this dispatcher in the events.
Properties
A dispatcher for blocking IO that is usable from common code, where Dispatchers.IO does not resolve.
Actual for JS: Dispatchers.Default, as there is no dedicated IO dispatcher.
Actual for JVM and Android: Dispatchers.IO.
Actual for Native targets: Dispatchers.IO.
Actual for Wasm (JS): Dispatchers.Default, as there is no dedicated IO dispatcher.
Actual for Wasm (WASI): Dispatchers.Default, as there is no dedicated IO dispatcher.
Actual for Android: thread identity and system-trace integration are true; TraceCapabilities.counters is true on API 29+; flows are not supported.
The tracing capabilities of the current target. Truthful, never throws; all flags are false on targets without a backend.
Actual for JS: no capability is available, every flag is false.
Actual for the JVM: only TraceCapabilities.threadIdentity is true. The Perfetto sink lives in the separate :runtime-tracing artifact.
Actual for Native: no capability is available, every flag is false.
Actual for Wasm (JS): no capability is available, every flag is false.
Actual for Wasm (WASI): no capability is available, every flag is false.
Functions
Creates a CompositeSink over sinks.
Hedged request: starts the primary attempt and, whenever the latest attempt has not completed within hedgeAfter, starts another identical attempt (up to maxAttempts in total). Returns the FIRST SUCCESSFUL result and cancels every attempt still running, so slower redundant requests never waste resources.
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.
The maximum concurrency of the traced dispatcher label, or null when unknown. Meant to feed PoolSampler's parallelism argument.
Actual for Android: returns a new AndroidTraceSink with default settings.
The default system-trace sink for the current target, or null when :runtime ships none (every target except Android). Null is the degraded answer, not an error: compose your own sinks.
Actual for JS: returns null, no system tracer ships with :runtime.
Actual for the JVM: returns null; use PerfettoTraceSink from :runtime-tracing for system-trace output.
Actual for Native: returns null, no system tracer ships with :runtime.
Actual for Wasm (JS): returns null, no system tracer ships with :runtime.
Actual for Wasm (WASI): returns null, no system tracer ships with :runtime.
Like runCatching, but never swallows a CancellationException.
Receiver variant of runCatchingCancellable: runs block with this as its receiver, capturing ordinary exceptions into a Result and rethrowing CancellationException.
Builds a Flow from a callback-based API while making cleanup impossible to forget.
Derives heuristic PoolSignals from these metrics using thresholds.
Derives heuristic PoolSignals from a chronological series of TraceEvent.PoolSamples, such as those a PoolSampler emits. Each label is evaluated on its own over its last minSamples samples; a label with fewer samples yields no signal.
Converts this flow into a StateFlow that only runs upstream while it has subscribers, plus a stopTimeoutMillis grace period after the last one leaves.
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.
Warm flow: a hybrid between cold and hot. The upstream does not start until the first collector asks for data, runs exactly once in scope, and memoizes every emitted value, so later (or concurrent) collectors replay the stored values and then follow the live upstream instead of re-running it.
Runs block with a timeout of timeoutMillis and reports a timeout as a failed Result instead of throwing, so it never cancels the parent scope.
Duration overload of withTimeoutResult.