Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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