Skip to content

Commit

Permalink
Add 'MsgRelease' to allow protocol to loop back to 'StIdle'
Browse files Browse the repository at this point in the history
  And seemingly, allow client to send 'Done' even after acquiring.
  • Loading branch information
KtorZ committed Oct 2, 2021
1 parent 2a22ab7 commit 3b847a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ data ClientStAcquired txid tx slot m a where
:: (slot -> m (ClientStAcquired txid tx slot m a))
-> ClientStAcquired txid tx slot m a

-- | Release the acquired snapshot, in order to loop back to the idle state.
--
SendMsgRelease
:: m (ClientStIdle txid tx slot m a)
-> ClientStAcquired txid tx slot m a

-- | Interpret a 'LocalTxMonitorClient' action sequence as a 'Peer' on the client
-- side of the 'LocalTxMonitor' protocol.
--
Expand All @@ -114,10 +120,6 @@ localTxMonitorClientPeer (LocalTxMonitorClient mClient) =
:: ClientStAcquired txid tx slot m a
-> Peer (LocalTxMonitor txid tx slot) AsClient StAcquired m a
handleStAcquired = \case
SendMsgReAcquire stAcquired ->
Yield (ClientAgency TokAcquired) MsgReAcquire $
Await (ServerAgency TokAcquiring) $ \case
MsgAcquired slot -> Effect $ handleStAcquired <$> stAcquired slot
SendMsgNextTx stAcquired ->
Yield (ClientAgency TokAcquired) MsgNextTx $
Await (ServerAgency (TokBusy TokBusyNext)) $ \case
Expand All @@ -126,3 +128,10 @@ localTxMonitorClientPeer (LocalTxMonitorClient mClient) =
Yield (ClientAgency TokAcquired) (MsgHasTx txid) $
Await (ServerAgency (TokBusy TokBusyHas)) $ \case
MsgReplyHasTx res -> Effect $ handleStAcquired <$> stAcquired res
SendMsgReAcquire stAcquired ->
Yield (ClientAgency TokAcquired) MsgReAcquire $
Await (ServerAgency TokAcquiring) $ \case
MsgAcquired slot -> Effect $ handleStAcquired <$> stAcquired slot
SendMsgRelease stIdle ->
Yield (ClientAgency TokAcquired) MsgRelease $
Effect $ handleStIdle <$> stIdle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ data ServerStAcquired txid tx slot m a = ServerStAcquired
{ recvMsgNextTx :: m (ServerStBusy StBusyNext txid tx slot m a)
, recvMsgHasTx :: txid -> m (ServerStBusy StBusyHas txid tx slot m a)
, recvMsgReAcquire :: m (ServerStAcquiring txid tx slot m a)
, recvMsgRelease :: m (ServerStIdle txid tx slot m a)
}

-- In the 'StBusy' protocol state, the server has agency and is responding to one of the client
Expand Down Expand Up @@ -121,14 +122,16 @@ localTxMonitorServerPeer (LocalTxMonitorServer mServer) =
:: ServerStAcquired txid tx slot m a
-> Peer (LocalTxMonitor txid tx slot) AsServer StAcquired m a
handleStAcquired = \case
ServerStAcquired{recvMsgNextTx, recvMsgHasTx, recvMsgReAcquire} ->
ServerStAcquired{recvMsgNextTx, recvMsgHasTx, recvMsgReAcquire, recvMsgRelease} ->
Await (ClientAgency TokAcquired) $ \case
MsgNextTx ->
Effect $ handleStBusyNext <$> recvMsgNextTx
MsgHasTx txid ->
Effect $ handleStBusyHas <$> recvMsgHasTx txid
MsgReAcquire ->
Effect $ handleStAcquiring <$> recvMsgReAcquire
MsgRelease ->
Effect $ handleStIdle <$> recvMsgRelease

handleStBusyNext
:: ServerStBusy StBusyNext txid tx slot m a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ instance Protocol (LocalTxMonitor txid tx slot) where
:: Bool
-> Message (LocalTxMonitor txid tx slot) (StBusy StBusyHas) StAcquired

-- | Release the acquired snapshot, in order to loop back to the idle state.
--
MsgRelease
:: Message (LocalTxMonitor txid tx slot) StAcquired StIdle

-- | The client can terminate the protocol.
--
MsgDone
Expand Down

0 comments on commit 3b847a0

Please sign in to comment.