Copyright | (c) axionbuster 2025 |
---|---|
License | BSD-3-Clause |
Safe Haskell | None |
Language | GHC2021 |
M.IO.Obs
Contents
Description
This module provides a general-purpose observer pattern implementation for monitoring and reacting to state changes in STM transactions.
Observer
Arguments
:: (MonadIO m, 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 -> m ()) | Action to execute when changes are detected, with old and new values Old value is passed first |
-> m 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