Created
November 25, 2018 04:02
-
-
Save snoyberg/d0625747054342848634089691d25a89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --resolver lts-12.18 script | |
import Control.Concurrent (threadDelay) | |
import Control.Concurrent.Async (replicateConcurrently_) | |
import Control.Monad (unless) | |
import Data.IORef | |
import System.Random (randomIO) | |
main :: IO () | |
main = do | |
ref <- newIORef (0 :: Int) | |
secret $ do | |
x <- randomIO | |
writeIORef ref x | |
threadDelay 1000 | |
y <- readIORef ref | |
unless (x == y) $ error "failure!" | |
putStrLn "All good!" | |
secret :: IO () -> IO () | |
secret = replicateConcurrently_ 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment