From 2087047626a11073883a40dabb48b9384d143f00 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Fri, 1 May 2026 13:07:38 +0400 Subject: [PATCH] agent: export withRetryIntervalLimit --- src/Simplex/FileTransfer/Agent.hs | 6 ------ src/Simplex/Messaging/Agent/RetryInterval.hs | 9 ++++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Simplex/FileTransfer/Agent.hs b/src/Simplex/FileTransfer/Agent.hs index a8b220327c..9a096f3146 100644 --- a/src/Simplex/FileTransfer/Agent.hs +++ b/src/Simplex/FileTransfer/Agent.hs @@ -250,12 +250,6 @@ runXFTPRcvWorker c srv Worker {doWork} = do | otherwise = 0 chunkReceived RcvFileChunk {replicas} = any received replicas --- The first call of action has n == 0, maxN is max number of retries -withRetryIntervalLimit :: forall m. MonadIO m => Int -> RetryInterval -> (Int64 -> m () -> m ()) -> m () -withRetryIntervalLimit maxN ri action = - withRetryIntervalCount ri $ \n delay loop -> - when (n < maxN) $ action delay loop - retryOnError :: Text -> AM a -> AM a -> AgentErrorType -> AM a retryOnError name loop done e = do logError $ name <> " error: " <> tshow e diff --git a/src/Simplex/Messaging/Agent/RetryInterval.hs b/src/Simplex/Messaging/Agent/RetryInterval.hs index 35fa7c5c68..e5f670d242 100644 --- a/src/Simplex/Messaging/Agent/RetryInterval.hs +++ b/src/Simplex/Messaging/Agent/RetryInterval.hs @@ -9,6 +9,7 @@ module Simplex.Messaging.Agent.RetryInterval RI2State (..), withRetryInterval, withRetryIntervalCount, + withRetryIntervalLimit, withRetryForeground, withRetryLock2, updateRetryInterval2, @@ -18,7 +19,7 @@ where import Control.Concurrent (forkIO) import Control.Concurrent.STM (retry) -import Control.Monad (void) +import Control.Monad (void, when) import Control.Monad.IO.Class (MonadIO, liftIO) import Data.Int (Int64) import Simplex.Messaging.Util (threadDelay', unlessM, whenM) @@ -65,6 +66,12 @@ withRetryIntervalCount ri action = callAction 0 0 $ initialInterval ri let elapsed' = elapsed + delay callAction (n + 1) elapsed' $ nextRetryDelay elapsed' delay ri +-- The first call of action has n == 0, maxN is max number of retries +withRetryIntervalLimit :: forall m. MonadIO m => Int -> RetryInterval -> (Int64 -> m () -> m ()) -> m () +withRetryIntervalLimit maxN ri action = + withRetryIntervalCount ri $ \n delay loop -> + when (n < maxN) $ action delay loop + withRetryForeground :: forall m a. MonadIO m => RetryInterval -> STM Bool -> STM Bool -> (Int64 -> m a -> m a) -> m a withRetryForeground ri isForeground isOnline action = callAction 0 $ initialInterval ri where