MutableFlowStore

interface MutableFlowStore<K : Any, V : Any, T> : FlowStore<K, V> (source)

Read/write view of a store-backed map. Every mutation takes the caller's transaction handle T: the write is enlisted on it through StoreWriter, which assigns the version, and the cache update and delta are published only when that transaction commits.

The owner must serialise writes to a given key (single-writer-per-key): the version is the store's commit order, so unserialised concurrent writes to one key would settle on the wrong version. Serialise at the transaction layer — a locking read such as SELECT … FOR UPDATE via Store.load, held across the transaction — not an in-process lock, which orders the calls but not the commits. V must be an aggregate root — see FlowStore.

Properties

Link copied to clipboard
abstract override val async: AsyncMutableFlowStore<K, V, T>

A suspending view of this store whose AsyncFlowStore.get dispatches the read-through itself.

Functions

Link copied to clipboard

The live, delta-only stream of versioned mutations.

abstract fun asFlow(query: () -> Map<K, Versioned<V>>, predicate: (K, V) -> Boolean = { _, _ -> true }): Flow<VersionedMapEvent<K, V>>

A get-and-subscribe view: emits the entries query loads now (as VersionedMapEvent.Upsert), then follows the live stream, version-gated per key so the snapshot and the tail never conflict. query is the bulk current state (key to value+version); it runs blocking on the store's dispatcher and is not written to the cache. predicate scopes the live tail to the same logical set: a live upsert that matches enters or updates the view, one that stops matching leaves it as a VersionedMapEvent.Removed, and removals forward only for keys in the view. query and predicate must agree (query = current rows matching predicate).

Link copied to clipboard
abstract fun get(key: K): V?

The latest value for key: cache-first, reading through to the store on a miss. The read-through is blocking — call it within an IO context, as with the store's writes. Not ordered against asFlow: a value just published as a delta may not be visible here yet.

abstract fun get(key: K, tx: T): V?

Reads key's current value within tx, always through the store and bypassing the cache, so it sees this transaction's own uncommitted writes and can take a locking read. Use for read-modify-write; use the cache-first get outside a transaction.

Link copied to clipboard
abstract fun put(key: K, value: V, tx: T)
Link copied to clipboard
abstract fun putAll(from: Map<K, V>, tx: T)
Link copied to clipboard
abstract fun remove(key: K, tx: T)
Link copied to clipboard
abstract fun valueFlow(key: K): Flow<V?>

The latest value for key, starting from a read-through load then following the stream.