StateSubscription

class StateSubscription<out T>(val initialSnapshot: StateSnapshot<T>, closeAction: () -> Unit) : AutoCloseable(source)

The atomic result of subscribing to a StateSource.

A source establishes observation before returning this handle. It may therefore invoke the callback before StateSource.subscribe returns; StateSubscription.initialSnapshot remains the observation at the subscription linearization point. Closing is idempotent and thread-safe. Concurrent callers wait for the one close action to finish and observe the same failure when it fails.

Parameters

closeAction

closes the source-owned observation and does not return successfully until the source can start no further callback for it.

Type Parameters

T

the observed value type.

Constructors

Link copied to clipboard
constructor(initialSnapshot: StateSnapshot<T>, closeAction: () -> Unit)

Properties

Link copied to clipboard

the value observed when the subscription was established.

Functions

Link copied to clipboard
open override fun close()

Closes this observation exactly once.