-
-
Save jonschoning/d397dba38a617321e16c44524cf799f5 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