# ProduceStateScope

Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ProduceState.kt+class:androidx.compose.runtime.ProduceStateScope) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0) Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  interface ProduceStateScope<T : Any?> : MutableState<T>, CoroutineScope
  ```

*** ** * ** ***

Receiver scope for use with `https://developer.android.com/reference/kotlin/androidx/compose/runtime/produceState.composable#produceState(kotlin.Any,kotlin.coroutines.SuspendFunction1)`.

## Summary

| ### Public functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-nothing/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#awaitDispose(kotlin.Function0)(onDispose: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` 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](https://developer.android.com/reference/kotlin/androidx/compose/runtime/MutableState) `operator T` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MutableState#component1()()` Cmn `operator (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MutableState#component2()()` Cmn

### Inherited properties

From [kotlinx.coroutines.CoroutineScope](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html` Cmn From [androidx.compose.runtime.MutableState](https://developer.android.com/reference/kotlin/androidx/compose/runtime/MutableState) `T` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MutableState#value()` Cmn

## Public functions

### awaitDispose

Cmn

```
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 `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProduceStateScope#awaitDispose(kotlin.Function0)` before resuming.

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

```kotlin
import androidx.compose.runtime.produceState

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

        awaitDispose { disposable.dispose() }
    }
```