BroadcastFrameClock

Class

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.

Functions

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.

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

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