module LiveCoding.Handle.Examples where
import Control.Concurrent
import Data.Data
import Data.IORef
import LiveCoding.Handle
ioRefHandle :: a -> Handle IO (IORef a)
ioRefHandle a = Handle
{ create = newIORef a
, destroy = const $ return ()
}
emptyMVarHandle :: Handle IO (MVar a)
emptyMVarHandle = Handle
{ create = newEmptyMVar
, destroy = const $ return ()
}
newMVarHandle :: a -> Handle IO (MVar a)
newMVarHandle a = Handle
{ create = newMVar a
, destroy = const $ return ()
}
threadHandle :: IO () -> Handle IO ThreadId
threadHandle action = Handle
{ create = forkIO action
, destroy = killThread
}