override suspend fun collect()

in hot-reload-core/src/main/kotlin/org/jetbrains/compose/reload/core/State.kt [46:61]


    override suspend fun collect(collector: suspend (T) -> Unit) {
        val none = Any()
        var lastEmittedValue: Any? = none

        try {
            while (isActive()) {
                val state = _value.get()
                if (none == lastEmittedValue || lastEmittedValue != state.value) {
                    lastEmittedValue = state.value
                    collector(state.value)
                }
                state.nextState.awaitOrThrow()
            }
        } catch (_: StopCollectingException) {
        }
    }