From 49eeceeb2f985ffd25749a1fa693bfef272ed657 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 29 Apr 2018 23:58:18 +0200 Subject: [PATCH] Misc --- ArchiSteamFarm/ArchiWebHandler.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 21116444b..ae8cb1c37 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -1937,21 +1937,22 @@ namespace ArchiSteamFarm { return await function().ConfigureAwait(false); } - // Sending a request affects both - number of requests as well as open connections - await limiters.RateLimitingSemaphore.WaitAsync().ConfigureAwait(false); + // Sending a request opens a new connection await limiters.OpenConnectionsSemaphore.WaitAsync().ConfigureAwait(false); - // We release rate-limiter semaphore regardless of our task completion, since we use that one only to guarantee rate-limiting of their creation - Utilities.InBackground(async () => { - await Task.Delay(Program.GlobalConfig.WebLimiterDelay).ConfigureAwait(false); - limiters.RateLimitingSemaphore.Release(); - }); - - // However, we release open connections semaphore only once we're indeed done sending a particular request - try { + // It also increases number of requests + await limiters.RateLimitingSemaphore.WaitAsync().ConfigureAwait(false); + + // We release rate-limiter semaphore regardless of our task completion, since we use that one only to guarantee rate-limiting of their creation + Utilities.InBackground(async () => { + await Task.Delay(Program.GlobalConfig.WebLimiterDelay).ConfigureAwait(false); + limiters.RateLimitingSemaphore.Release(); + }); + return await function().ConfigureAwait(false); } finally { + // We release open connections semaphore only once we're indeed done sending a particular request limiters.OpenConnectionsSemaphore.Release(); } }