Skip to content

Instantly share code, notes, and snippets.

@snoyberg
Created November 25, 2018 04:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save snoyberg/d0625747054342848634089691d25a89 to your computer and use it in GitHub Desktop.
Save snoyberg/d0625747054342848634089691d25a89 to your computer and use it in GitHub Desktop.
#!/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