mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-03-30 16:26:02 +00:00
18 lines
797 B
Markdown
18 lines
797 B
Markdown
# Simplex.Messaging.TMap
|
|
|
|
> STM-safe concurrent map (`TVar (Map k a)`).
|
|
|
|
**Source**: [`TMap.hs`](../../../../src/Simplex/Messaging/TMap.hs)
|
|
|
|
## lookupInsert / lookupDelete
|
|
|
|
Atomic swap operations using `stateTVar` + `alterF`. `lookupInsert` returns the previous value (if any) while inserting the new one; `lookupDelete` returns the value while removing it. Both are single STM operations — no window between lookup and modification.
|
|
|
|
## union
|
|
|
|
Left-biased: the passed-in `Map` wins on key conflicts. `union additions tmap` overwrites existing keys in `tmap` with values from `additions`.
|
|
|
|
## alterF
|
|
|
|
The STM action `f` runs inside the same STM transaction. If `f` retries, the entire `alterF` retries. If `f` has side effects via other TVars, they compose atomically with the map modification.
|