module Simulation.Aivika.Trans.GPSS.Block.Link
(linkBlock) where
import Simulation.Aivika.Trans
import Simulation.Aivika.Trans.GPSS.Block
linkBlock :: MonadDES m
=> (a -> Process m (Either (Block m a ()) Bool))
-> Block m a a
{-# INLINABLE linkBlock #-}
linkBlock :: forall (m :: * -> *) a.
MonadDES m =>
(a -> Process m (Either (Block m a ()) Bool)) -> Block m a a
linkBlock a -> Process m (Either (Block m a ()) Bool)
f =
Block { blockProcess :: a -> Process m a
blockProcess = \a
a ->
do Either (Block m a ()) Bool
x <- a -> Process m (Either (Block m a ()) Bool)
f a
a
case Either (Block m a ()) Bool
x of
Left Block m a ()
transfer ->
forall (m :: * -> *) a. MonadDES m => Process m () -> Process m a
transferProcess forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a b. Block m a b -> a -> Process m b
blockProcess Block m a ()
transfer a
a
Right Bool
False ->
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
Right Bool
True ->
do forall (m :: * -> *). MonadDES m => Process m ()
passivateProcess
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
}