{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
module Network.TypedProtocol.PingPong.Server where
import Network.TypedProtocol.Core
import Network.TypedProtocol.Peer.Server
import Network.TypedProtocol.PingPong.Type
data PingPongServer m a = PingPongServer {
forall (m :: * -> *) a.
PingPongServer m a -> m (PingPongServer m a)
recvMsgPing :: m (PingPongServer m a)
, forall (m :: * -> *) a. PingPongServer m a -> a
recvMsgDone :: a
}
pingPongServerPeer
:: Monad m
=> PingPongServer m a
-> Server PingPong NonPipelined StIdle m a
pingPongServerPeer :: forall (m :: * -> *) a.
Monad m =>
PingPongServer m a -> Server PingPong 'NonPipelined 'StIdle m a
pingPongServerPeer PingPongServer{a
m (PingPongServer m a)
recvMsgPing :: forall (m :: * -> *) a.
PingPongServer m a -> m (PingPongServer m a)
recvMsgDone :: forall (m :: * -> *) a. PingPongServer m a -> a
recvMsgPing :: m (PingPongServer m a)
recvMsgDone :: a
..} =
(forall (st' :: PingPong).
Message PingPong 'StIdle st'
-> Server PingPong 'NonPipelined st' m a)
-> Server PingPong 'NonPipelined 'StIdle m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a.
(StateTokenI st, StateAgency st ~ 'ClientAgency,
Outstanding pl ~ 'Z) =>
(forall (st' :: ps). Message ps st st' -> Server ps pl st' m a)
-> Server ps pl st m a
Await ((forall (st' :: PingPong).
Message PingPong 'StIdle st'
-> Server PingPong 'NonPipelined st' m a)
-> Server PingPong 'NonPipelined 'StIdle m a)
-> (forall (st' :: PingPong).
Message PingPong 'StIdle st'
-> Server PingPong 'NonPipelined st' m a)
-> Server PingPong 'NonPipelined 'StIdle m a
forall a b. (a -> b) -> a -> b
$ \Message PingPong 'StIdle st'
req ->
case Message PingPong 'StIdle st'
req of
Message PingPong 'StIdle st'
R:MessagePingPongfromto 'StIdle st'
MsgDone -> a -> Server PingPong 'NonPipelined st' m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a.
(StateTokenI st, StateAgency st ~ 'NobodyAgency,
Outstanding pl ~ 'Z) =>
a -> Server ps pl st m a
Done a
recvMsgDone
Message PingPong 'StIdle st'
R:MessagePingPongfromto 'StIdle st'
MsgPing -> m (Server PingPong 'NonPipelined st' m a)
-> Server PingPong 'NonPipelined st' m a
forall ps (pl :: IsPipelined) (st :: ps) (m :: * -> *) a.
m (Server ps pl st m a) -> Server ps pl st m a
Effect (m (Server PingPong 'NonPipelined st' m a)
-> Server PingPong 'NonPipelined st' m a)
-> m (Server PingPong 'NonPipelined st' m a)
-> Server PingPong 'NonPipelined st' m a
forall a b. (a -> b) -> a -> b
$ do
next <- m (PingPongServer m a)
recvMsgPing
pure $ Yield MsgPong (pingPongServerPeer next)