observeFlow
Collects flow with both an event budget and a real-time budget.
Stops when until accepts an event, when maxCount events have arrived, when the flow completes, or when timeout passes, and reports which one happened. The timeout runs on Dispatchers.Default, so it measures real time even inside runTest; collection stays on the caller's dispatcher. Zero budgets collect nothing. The budget starts before collection, including synchronous upstream work. Collection must cooperate with cancellation; a timeout cannot interrupt blocking or non-cooperative code. An event that arrives after the timeout is never recorded, including on single-threaded targets such as JS, where the timer cannot run until the upstream suspends.
val observation = observeFlow(viewModel.state, maxCount = 5, timeout = 2.seconds) { it.isLoaded }
assertEquals(FlowObservation.End.MATCHED, observation.end)Return
Collected events and the stopping reason.
Parameters
The flow to collect; its failures propagate unchanged.
The nonnegative event budget.
The nonnegative real-time budget.
Stops observation when it returns true; defaults to collecting up to the limit.