ProduceStateScope


Receiver scope for use with produceState.

Summary

Public functions

suspend Nothing
awaitDispose(onDispose: () -> Unit)

Await the disposal of this producer whether it left the composition, the source changed, or an error occurred.

Cmn

Inherited functions

From androidx.compose.runtime.MutableState
operator T
Cmn
operator (T) -> Unit
Cmn

Public functions

awaitDispose

suspend fun awaitDispose(onDispose: () -> Unit): Nothing

Await the disposal of this producer whether it left the composition, the source changed, or an error occurred. Always runs onDispose before resuming.

This method is useful when configuring callback-based state producers that do not suspend, for example:

import androidx.compose.runtime.produceState

val currentPerson by
    produceState<Person?>(null, viewModel) {
        val disposable = viewModel.registerPersonObserver { person -> value = person }

        awaitDispose { disposable.dispose() }
    }