RecordingBudgetObserver

A BudgetObserver that records every event, the worked example of the seam (the @OptIn on this class is exactly the line a consumer's own implementation needs).

Stable Core, source compatibility only. Thread-safe: events from concurrent calls are appended to a copy-on-write list. onEach, when given, runs for every event after it is recorded, on the thread of the call that produced it, so a test can make the observer call back into the budget. toString() prints the event count.

Parameters

onEach

an extra callback per event; does nothing by default. An exception it throws propagates to the budget, which logs it.

Constructors

Link copied to clipboard
constructor(onEach: (BudgetEvent) -> Unit = {})

Properties

Link copied to clipboard

Every event so far, in the order they arrived; a snapshot.

Functions

Link copied to clipboard
fun clear()

Forgets every recorded event.

Link copied to clipboard
inline fun <reified E : BudgetEvent> eventsOf(): List<E>

The recorded events of type E, in order.

Link copied to clipboard
open override fun onEvent(event: BudgetEvent)

Records event, in arrival order, for later inspection through events, then runs onEach with it on the calling thread.

Link copied to clipboard
open override fun toString(): String

A diagnostic string for logs: the number of recorded events. Its format is not part of the API and may change.