# BroadcastFrameClock

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

  ```
  class BroadcastFrameClock : MonotonicFrameClock
  ```

*** ** * ** ***

A simple frame clock.

This implementation is intended for low-contention environments involving low total numbers of threads in a pool on the order of \~number of CPU cores available for UI recomposition work, while avoiding additional allocation where possible.

`https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#onNewAwaiters()` will be invoked whenever the number of awaiters has changed from 0 to 1. If `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#onNewAwaiters()` **fails** by throwing an exception it will permanently fail this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock`; all current and future awaiters will resume with the thrown exception.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#BroadcastFrameClock(kotlin.Function0)(onNewAwaiters: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?)` | Cmn |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#cancel(kotlin.coroutines.cancellation.CancellationException)(cancellationException: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines.cancellation/-cancellation-exception/index.html)` Permanently cancel this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock` and cancel all current and future awaiters with `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#cancel(kotlin.coroutines.cancellation.CancellationException)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#sendFrame(kotlin.Long)(timeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Send a frame for time `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#sendFrame(kotlin.Long)` to all current callers of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#withFrameNanos(kotlin.Function1)`. | Cmn |
| `open suspend R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#withFrameNanos(kotlin.Function1)(onFrame: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) -> R)` Suspends until a new frame is requested, immediately invokes `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)` with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)`. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#hasAwaiters()` `true` if there are any callers of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#withFrameNanos(kotlin.Function1)` awaiting to run for a pending frame. | Cmn |

### Inherited functions

From [kotlin.coroutines.CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html) `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/plus.html(context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)` Cmn From [kotlin.coroutines.CoroutineContext.Element](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html) `open R` `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/fold.html(initial: R, operation: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html, R) -> R)` Cmn `open operator E?` `<E : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/index.html> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/get.html(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<E>)` Cmn `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-element/minus-key.html(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<*>)` Cmn

### Inherited properties

From [androidx.compose.runtime.MonotonicFrameClock](https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock) `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/-key/index.html<*>` `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#key()` Cmn

## Public constructors

### BroadcastFrameClock

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

```
BroadcastFrameClock(onNewAwaiters: (() -> Unit)? = null)
```

## Public functions

### cancel

Cmn

```
fun cancel(
    cancellationException: CancellationException = CancellationException("clock cancelled")
): Unit
```

Permanently cancel this `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock` and cancel all current and future awaiters with `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#cancel(kotlin.coroutines.cancellation.CancellationException)`.

### sendFrame

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

```
fun sendFrame(timeNanos: Long): Unit
```

Send a frame for time `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#sendFrame(kotlin.Long)` to all current callers of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#withFrameNanos(kotlin.Function1)`. The `onFrame` callback for each caller is invoked synchronously during the call to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#sendFrame(kotlin.Long)`.

### withFrameNanos

Cmn

```
open suspend fun <R : Any?> withFrameNanos(onFrame: (Long) -> R): R
```

Suspends until a new frame is requested, immediately invokes `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)` with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)`.

`frameTimeNanos` should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame, not necessarily a direct, "now" value.

The time base of the value provided by `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)` is implementation defined. Time values provided are strictly monotonically increasing; after a call to `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MonotonicFrameClock#withFrameNanos(kotlin.Function1)` completes it must not provide the same value again for a subsequent call.

## Public properties

### hasAwaiters

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

```
val hasAwaiters: Boolean
```

`true` if there are any callers of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/BroadcastFrameClock#withFrameNanos(kotlin.Function1)` awaiting to run for a pending frame.