# Recomposer

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/Recomposer.kt+class:androidx.compose.runtime.Recomposer) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0) Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  class Recomposer : CompositionContext
  ```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.compose.runtime.CompositionContext](https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionContext) ||
|   | ↳ | [androidx.compose.runtime.Recomposer](https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer) |

*** ** * ** ***

The scheduler for performing recomposition and applying updates to one or more `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition`s.

## Summary

| ### Nested types |
|---|
| `enum https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State>` Valid operational states of a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. |

| ### Public companion properties |
|---|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/compose/runtime/RecomposerInfo>>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runningRecomposers()` An observable `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html` of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/RecomposerInfo`s for currently `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runRecomposeAndApplyChanges()` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`s. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#Recomposer(kotlin.coroutines.CoroutineContext)(effectCoroutineContext: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)` | Cmn |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/RecomposerInfo` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#asRecomposerInfo()()` Obtain a read-only `https://developer.android.com/reference/kotlin/androidx/compose/runtime/RecomposerInfo` for this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#awaitIdle()()` Suspends until the currently pending recomposition frame is complete. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#cancel()()` Permanently shut down this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` for future use. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#close()()` Close this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#join()()` Await the completion of a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#cancel()` operation. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#pauseCompositionFrameClock()()` Pause broadcasting the frame clock while recomposing. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#resumeCompositionFrameClock()()` Resume broadcasting the frame clock after is has been paused. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runRecomposeAndApplyChanges()()` Await the invalidation of any associated `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composer`s, recompose them, and apply their changes to their associated `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition`s if recomposition is successful. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/runtime/CancellationHandle` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)(action: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Schedules an `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)` to be invoked when the recomposer finishes the next composition of a frame (including the completion of subcompositions). | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#changeCount()` This is a running count of the number of times the recomposer awoke and applied changes to one or more composers. | Cmn |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html<https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#currentState()` The current `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State` of this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`, available synchronously. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#effectCoroutineContext()` The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#effectCoroutineContext()` is derived from the parameter of the same name. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#hasPendingWork()` `true` if this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` has any pending work scheduled, regardless of whether or not it is currently `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runRecomposeAndApplyChanges()`. | Cmn |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#state()` **This property is deprecated.** Replaced by currentState as a StateFlow | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionObserverHandle` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/ExperimentalComposeRuntimeApi https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#(androidx.compose.runtime.Recomposer).observe(androidx.compose.runtime.tooling.CompositionRegistrationObserver)(observer: https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionRegistrationObserver)` Register an observer to be notified when a composition is added to or removed from the given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. | Cmn |

## Public companion properties

### runningRecomposers

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
val runningRecomposers: StateFlow<Set<RecomposerInfo>>
```

An observable `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html` of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/RecomposerInfo`s for currently `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runRecomposeAndApplyChanges()` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`s. Emitted sets are immutable.

## Public constructors

### Recomposer

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
Recomposer(effectCoroutineContext: CoroutineContext)
```

## Public functions

### asRecomposerInfo

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
fun asRecomposerInfo(): RecomposerInfo
```

Obtain a read-only `https://developer.android.com/reference/kotlin/androidx/compose/runtime/RecomposerInfo` for this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`.

### awaitIdle

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
suspend fun awaitIdle(): Unit
```

Suspends until the currently pending recomposition frame is complete. Any recomposition for this recomposer triggered by actions before this call begins will be complete and applied (if recomposition was successful) when this call returns.

If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runRecomposeAndApplyChanges()` is not currently running the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` is considered idle and this method will not suspend.

### cancel

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
fun cancel(): Unit
```

Permanently shut down this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` for future use. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#currentState()` will immediately reflect `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State#ShuttingDown` (or a lower state) before this call returns. All ongoing recompositions will stop, new composer invalidations with this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` at the root will no longer occur, and any `https://developer.android.com/reference/kotlin/androidx/compose/runtime/LaunchedEffect.composable#LaunchedEffect(kotlin.coroutines.SuspendFunction1)`s currently running in compositions managed by this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` will be cancelled. Any `https://developer.android.com/reference/kotlin/androidx/compose/runtime/rememberCoroutineScope.composable#rememberCoroutineScope(kotlin.Function0)` scopes from compositions managed by this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` will also be cancelled. See `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#join()` to await the completion of all of these outstanding tasks.

### close

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
fun close(): Unit
```

Close this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. Once all effects launched by managed compositions complete, any active call to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runRecomposeAndApplyChanges()` will return normally and this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` will be `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State#ShutDown`. See `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#join()` to await the completion of all of these outstanding tasks.

### join

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
suspend fun join(): Unit
```

Await the completion of a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#cancel()` operation.

### pauseCompositionFrameClock

Cmn Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.5.0)

```
fun pauseCompositionFrameClock(): Unit
```

Pause broadcasting the frame clock while recomposing. This effectively pauses animations, or any other use of the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#withFrameNanos(kotlin.Function1)`, while the frame clock is paused.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#pauseCompositionFrameClock()` should be called when the recomposer is not being displayed for some reason such as not being the current activity in Android, for example.

Calls to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#pauseCompositionFrameClock()` are thread-safe and idempotent (calling it when the frame clock is already paused is a no-op).

### resumeCompositionFrameClock

Cmn Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.5.0)

```
fun resumeCompositionFrameClock(): Unit
```

Resume broadcasting the frame clock after is has been paused. Pending calls to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#withFrameNanos(kotlin.Function1)` will start receiving frame clock broadcasts at the beginning of the frame and a frame will be requested if there are pending calls to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#withFrameNanos(kotlin.Function1)` if a frame has not already been scheduled.

Calls to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#resumeCompositionFrameClock()` are thread-safe and idempotent (calling it when the frame clock is running is a no-op).

### runRecomposeAndApplyChanges

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
suspend fun runRecomposeAndApplyChanges(): Unit
```

Await the invalidation of any associated `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composer`s, recompose them, and apply their changes to their associated `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition`s if recomposition is successful.

While `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runRecomposeAndApplyChanges()` is running, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#awaitIdle()` will suspend until there are no more invalid composers awaiting recomposition.

This method will not return unless the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` is `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#close()`d and all effects in managed compositions complete. Unhandled failure exceptions from child coroutines will be thrown by this method.

### scheduleFrameEndCallback

Cmn

```
open fun scheduleFrameEndCallback(action: () -> Unit): CancellationHandle
```

Schedules an `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)` to be invoked when the recomposer finishes the next composition of a frame (including the completion of subcompositions). If a frame is currently in-progress, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)` will be invoked when the current frame fully finishes composing. If a frame isn't currently in-progress, a new frame will be scheduled (if one hasn't been already) and `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)` will execute at the completion of the next frame's composition. If a new frame is scheduled and there is no other work to execute, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)` will still execute.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)` will always execute on the applier thread.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/CancellationHandle` | A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/CancellationHandle` that can be used to unregister the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)`. The returned handle is thread-safe and may be cancelled from any thread. Cancelling the handle only removes the callback from the queue. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#scheduleFrameEndCallback(kotlin.Function0)` is currently executing, it will not be cancelled by this handle. |

## Public properties

### changeCount

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
val changeCount: Long
```

This is a running count of the number of times the recomposer awoke and applied changes to one or more composers. This count is unaffected if the composer awakes and recomposed but composition did not produce changes to apply.

### currentState

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.1.0)

```
val currentState: StateFlow<Recomposer.State>
```

The current `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State` of this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`, available synchronously.

### effectCoroutineContext

Cmn

```
open val effectCoroutineContext: CoroutineContext
```

The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#effectCoroutineContext()` is derived from the parameter of the same name.

### hasPendingWork

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
val hasPendingWork: Boolean
```

`true` if this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` has any pending work scheduled, regardless of whether or not it is currently `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer#runRecomposeAndApplyChanges()`.

### state

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.1.0)

```
val state: Flow<Recomposer.State>
```

> [!CAUTION]
> **This property is deprecated.**   
> Replaced by currentState as a StateFlow, use this instead:
>
> ```kotlin
> currentState
> ```

The current `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State` of this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. See each `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer.State` value for its meaning.

## Extension functions

### Recomposer.observe

Cmn 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/tooling/CompositionObserver.kt+function:observe)

```
@ExperimentalComposeRuntimeApi
fun Recomposer.observe(observer: CompositionRegistrationObserver): CompositionObserverHandle
```

Register an observer to be notified when a composition is added to or removed from the given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. When this method is called, the observer will be notified of all currently registered compositions per the documentation in `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionRegistrationObserver#onCompositionRegistered(androidx.compose.runtime.tooling.ObservableComposition)`.

| Parameters |
|---|---|
| `observer: https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionRegistrationObserver` | the observer that will be informed of new compositions registered with this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionObserverHandle` | a handle that allows the observer to be disposed and detached from the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`. |