StateFlowTable

class StateFlowTable<ID0 : Any, ID1 : Any, V : Any> constructor(clock: <Error class: unknown class>)

A two-level concurrent state table based on MutableStateFlow.

  • The first level (ID0) groups entries into sub-tables.

  • The second level (ID1) holds values of type V along with their timestamp (WithTimestamp).

Each sub-table is a MutableStateFlow of a map, so updates can be observed reactively.

Parameters

ID0

the type of the outer key

ID1

the type of the inner key

V

the type of the stored value

Constructors

Link copied to clipboard
constructor()

Default constructor that uses the system clock.

constructor(clock: <Error class: unknown class>)

Functions

Link copied to clipboard
suspend fun drop(id0: ID0, id1: ID1)

Removes a specific entry identified by id0 and id1.

Link copied to clipboard
suspend fun dropAllBefore(timestamp: <Error class: unknown class>)

Removes all entries (across all IDs) that were set before the given timestamp.

Link copied to clipboard
suspend fun get(id: ID0): <Error class: unknown class><Map<ID1, WithTimestamp<V>>>

Gets the current state flow for the given id.

Link copied to clipboard
suspend fun set(id0: ID0, id1: ID1, value: V)

Sets a new value for the given id0 and id1.

Link copied to clipboard
fun subscribe(id: ID0): <Error class: unknown class><StateEvent<ID1, V>>

Subscribes to changes for all entries under the given id.

Link copied to clipboard
suspend fun update(id0: ID0, id1: ID1, block: (ID1, V?) -> V?)

Updates the entry for the given id0 and id1 using block.