Files
simplexmq/spec/modules/Simplex/Messaging/TMap.md
Evgeny @ SimpleX Chat 66d7efa61e some modules documented
2026-03-11 08:53:57 +00:00

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.