From ba50676a1fe66c5f24f251984f2cb49c0e98aead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Thu, 28 Jul 2022 21:29:37 +0200 Subject: Service: wait with output after head commit --- src/Service.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Service.hs') diff --git a/src/Service.hs b/src/Service.hs index 96fa63d..3ef10d6 100644 --- a/src/Service.hs +++ b/src/Service.hs @@ -18,6 +18,7 @@ module Service ( svcPrint, replyPacket, replyStored, replyStoredRef, + afterCommit, ) where import Control.Monad.Except @@ -101,6 +102,7 @@ data ServiceInput s = ServiceInput } data ServiceReply s = ServiceReply (Either s (Stored s)) Bool + | ServiceFinally (IO ()) data ServiceHandlerState s = ServiceHandlerState { svcValue :: ServiceState s @@ -163,7 +165,7 @@ svcSelf = maybe (throwError "failed to validate own identity") return . validateIdentity . lsIdentity . fromStored =<< svcGetLocal svcPrint :: String -> ServiceHandler s () -svcPrint str = liftIO . ($str) =<< asks svcPrintOp +svcPrint str = afterCommit . ($str) =<< asks svcPrintOp replyPacket :: Service s => s -> ServiceHandler s () replyPacket x = tell [ServiceReply (Left x) True] @@ -173,3 +175,6 @@ replyStored x = tell [ServiceReply (Right x) True] replyStoredRef :: Service s => Stored s -> ServiceHandler s () replyStoredRef x = tell [ServiceReply (Right x) False] + +afterCommit :: IO () -> ServiceHandler s () +afterCommit x = tell [ServiceFinally x] -- cgit v1.2.3