{-# LANGUAGE ExistentialQuantification, FlexibleContexts, TypeOperators #-}
module Test.IOSpec.Fork
(
ForkS
, forkIO
)
where
import Test.IOSpec.VirtualMachine
import Test.IOSpec.Types
data ForkS a =
forall f b . Executable f => Fork (IOSpec f b) (ThreadId -> a)
instance Functor ForkS where
fmap f (Fork l io) = Fork l (f . io)
forkIO :: (Executable f, ForkS :<: g) => IOSpec f a -> IOSpec g ThreadId
forkIO p = inject (Fork p return)
instance Executable ForkS where
step (Fork t p) = do
tid <- freshThreadId
updateSoup tid t
return (Step (p tid))