Skip to content

Instantly share code, notes, and snippets.

@alllex
Created October 22, 2015 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alllex/d12f990d9205650f1850 to your computer and use it in GitHub Desktop.
Save alllex/d12f990d9205650f1850 to your computer and use it in GitHub Desktop.
Main file for stm-data-collection-test
import Control.Monad ( forM_ )
import Control.Concurrent.STM
import qualified Data.STM.Bag as Bag
import qualified Data.STM.PriorityQueue as PQ
pqTest :: IO ()
pqTest = do
putStrLn "Start priority queue test"
pq <- atomically $ (PQ.new :: STM (PQ.Impl Int Int))
let kvs = [(2, 1), (5, 3), (1, 2), (4, 5)]
forM_ kvs $ \(k, v) -> atomically $ PQ.insert pq k v
x <- atomically $ PQ.deleteMin pq
putStrLn $ "Must print 2"
putStrLn $ "x = " ++ show x
bagTest :: IO ()
bagTest = do
putStrLn "Start bag test"
bag <- atomically $ (Bag.new :: STM (Bag.Impl Int))
atomically $ Bag.add bag 7
atomically $ Bag.add bag 5
x <- atomically $ Bag.take bag
putStrLn $ "Must print 5 or 7"
putStrLn $ "x = " ++ show x
main :: IO ()
main = do
bagTest
pqTest
putStrLn "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment