acme-missiles-0.3: Cause serious international side effects.

Safe HaskellSafe-Infered




Launching missiles in the STM monad

withMissilesDo :: IO a -> IO aSource

Perform initialization needed to launch missiles in the STM monad.

launchMissilesSTM :: STM ()Source

Launch missiles within an STM computation. Even if the memory transaction is retried, only one salvo of missiles will be launched.


import Acme.Missiles
import Control.Concurrent
import Control.Concurrent.STM

main :: IO ()
main = withMissilesDo $ do
    xv <- atomically $ newTVar (2 :: Int)
    yv <- atomically $ newTVar (1 :: Int)
    atomically $ do
        x <- readTVar xv
        y <- readTVar yv
        if x > y
            then launchMissilesSTM
            else return ()
    threadDelay 100000