subscribe

abstract fun subscribe(observer: (StateSnapshot<T>) -> Unit): StateSubscription<T>(source)

Establishes one observation and returns its initial value and close handle.

Return

the initial snapshot and an idempotent handle for this observation.

Parameters

observer

receives newer snapshots and may run on any thread; it must return normally.

Throws

when establishment fails before its linearization point; no observer callback starts and no resource transfers to the caller in that case.