Class

BroadcastFrameClock

A simple frame clock.

Source set: Common
public class BroadcastFrameClock(private val onNewAwaiters: (() -> Unit)? = null) :
    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.

onNewAwaiters will be invoked whenever the number of awaiters has changed from 0 to 1. If onNewAwaiters fails by throwing an exception it will permanently fail this BroadcastFrameClock; all current and future awaiters will resume with the thrown exception.

Properties

hasAwaiters

Source set: Common
public val hasAwaiters: Boolean

true if there are any callers of withFrameNanos awaiting to run for a pending frame.

Functions

sendFrame

Source set: Common
public fun sendFrame(timeNanos: Long)

Send a frame for time timeNanos to all current callers of withFrameNanos. The onFrame callback for each caller is invoked synchronously during the call to sendFrame.

withFrameNanos

Source set: Common
override suspend fun <R> withFrameNanos(onFrame: (Long) -> R): R

cancel

Source set: Common
public fun cancel(
        cancellationException: CancellationException = CancellationException("clock cancelled")
    )

Permanently cancel this BroadcastFrameClock and cancel all current and future awaiters with cancellationException.

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: