stateFlow

fun SleepTimer.stateFlow(intervalMs: Long = 50): Flow<SleepTimerState>

Observes the timer's SleepTimerState as a cold Flow.

Emits the current state immediately, then polls SleepTimer.state every intervalMs milliseconds and emits on change. Completes when the timer reaches SleepTimerState.COMPLETED. Cancel and close leave the timer SleepTimerState.IDLE; this flow keeps polling so a later SleepTimer.schedule is still visible. Cancel the collector to stop.

Parameters

intervalMs

Polling interval in milliseconds. Default is 50 ms.

See also


fun AudioStream.stateFlow(intervalMs: Long = 50): Flow<StreamState>

Observes the stream's StreamState as a cold Flow.

The flow emits the current state immediately, then polls AudioStream.state every intervalMs milliseconds and emits again when the state changes. Collection stops when the stream reaches StreamState.CLOSED or the collector is cancelled.

This is a cold flow: nothing is polled until it is collected, and each collector has its own polling loop bound to that collector's coroutine. Capture the flow in a variable if several collectors should share the same instance, or use stateIn to convert it to a kotlinx.coroutines.flow.StateFlow.

Usage

val stream = engine.openStream(config, callback)
scope.launch {
stream.stateFlow().collect { streamState ->
println("Stream state: $streamState")
}
}
stream.start()

Parameters

intervalMs

Polling interval in milliseconds. Default is 50 ms.

See also