Google is committed to advancing racial equity for Black communities. See how.

ProduceStateScope

interface ProduceStateScope<T> : MutableState<T>, CoroutineScope
androidx.compose.runtime.ProduceStateScope

Receiver scope for use with produceState.

Summary

Public methods
abstract suspend Nothing
awaitDispose(onDispose: () -> Unit)

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

Inherited functions
Inherited extension functions
From androidx.compose.runtime
operator T
State<T>.getValue(thisObj: Any?, property: KProperty<*>)

Permits property delegation of vals using by for State.

operator Unit
MutableState<T>.setValue(thisObj: Any?, property: KProperty<*>, value: T)

Permits property delegation of vars using by for MutableState.

Inherited properties

Public methods

awaitDispose

abstract 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()
    }
}