Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Concurrent (threadDelay)
import Control.LVish
import Control.LVish.DeepFrz
import Control.LVish.Internal (liftIO)
import Data.LVar.IVar
import Data.LVar.Counter
import Data.Word
lessthan :: (HasGet e, HasPut e, HasBump e) => Word -> Par e s (IVar s Bool)
lessthan w = do
r <- new
c <- newCounter 0
fork $ (waitThresh c w >> put r True)
fork $ (doSomeWork c)
-- note that this is just `return r`, not `get r`
return r
doSomeWork c = do
liftIO $ threadDelay 1000000
increment c 3
main = do
let v = runParThenFreeze $ lessthan 4
print $ case (fromIVar v) of
Nothing -> False
Just True -> True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.