Copyright | (c) axionbuster 2025 |
---|---|
License | BSD-3-Clause |
Safe Haskell | None |
Language | GHC2021 |
This module provides a general-purpose observer pattern implementation for monitoring and reacting to state changes in STM transactions.
Observer
:: forall (es :: [Effect]) a b. (Concurrent :> es, Eq a) | |
=> TVar a | Target variable to observe for changes |
-> (a -> a -> STM a) | Function to compare and transform old and new values in STM Old value is passed first; returned value gets committed and remembered |
-> (a -> a -> Eff es ()) | Action to execute when changes are detected, with old and new values Old value is passed first |
-> Eff es b |
A general observer that monitors changes in a shared variable and reacts to them.
The observer watches a target variable for changes, compares values using a custom comparison function, and executes an action when changes are detected.
obs targetvar -- Variable to observe compareandtransform -- STM function to compare and transform values reacttochange -- Action to execute when changes occur