diff options
Diffstat (limited to 'app/Util.hs')
-rw-r--r-- | app/Util.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/Util.hs b/app/Util.hs new file mode 100644 index 0000000..308ef88 --- /dev/null +++ b/app/Util.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE BlockArguments #-} + +module Util + ( stmChanges, + ) +where + +import UnliftIO.STM + +stmChanges :: (Eq a) => STM a -> IO (STM a) +stmChanges mkX = do + x'T <- newTVarIO Nothing + pure do + x' <- readTVar x'T + x <- mkX + checkSTM (Just x /= x') + writeTVar x'T (Just x) + pure x |