From e07bedac0e59346f076d71635ce6cd25de67ca7e Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:01:54 +0100 Subject: [PATCH] move tryError to Simplex.Messaging.Util (#191) --- src/Simplex/Messaging/Agent.hs | 3 +-- src/Simplex/Messaging/Util.hs | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index 1dd0b4c77..6b003250c 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -83,7 +83,7 @@ import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Protocol (MsgBody, SenderPublicKey) import qualified Simplex.Messaging.Protocol as SMP import Simplex.Messaging.Transport (ATransport (..), TProxy, Transport (..), runTransportServer) -import Simplex.Messaging.Util (bshow) +import Simplex.Messaging.Util (bshow, tryError) import System.Random (randomR) import UnliftIO.Async (Async, async, race_) import qualified UnliftIO.Exception as E @@ -427,7 +427,6 @@ runSrvMsgDelivery c@AgentClient {subQ} srv = do notify connId $ SENT mId withStore $ \st -> updateSndMsgStatus st connId msgId SndMsgSent where - tryError action = (Right <$> action) `catchError` (pure . Left) notify :: ConnId -> ACommand 'Agent -> m () notify connId cmd = atomically $ writeTBQueue subQ ("", connId, cmd) diff --git a/src/Simplex/Messaging/Util.hs b/src/Simplex/Messaging/Util.hs index 2800e521e..5bd05c4a9 100644 --- a/src/Simplex/Messaging/Util.hs +++ b/src/Simplex/Messaging/Util.hs @@ -50,3 +50,6 @@ liftError f = liftEitherError f . runExceptT liftEitherError :: (MonadIO m, MonadError e' m) => (e -> e') -> IO (Either e a) -> m a liftEitherError f a = liftIOEither (first f <$> a) + +tryError :: MonadError e m => m a -> m (Either e a) +tryError action = (Right <$> action) `catchError` (pure . Left)