From ab8a93d1e2c745c0097119d07dad422df6a79503 Mon Sep 17 00:00:00 2001 From: JKorf Date: Wed, 3 Dec 2025 21:39:11 +0100 Subject: [PATCH] wip --- CryptoExchange.Net/Clients/RestApiClient.cs | 9 ++++----- .../RateLimiting/Interfaces/IRateLimitGate.cs | 4 ++-- CryptoExchange.Net/RateLimiting/RateLimitGate.cs | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CryptoExchange.Net/Clients/RestApiClient.cs b/CryptoExchange.Net/Clients/RestApiClient.cs index 914f6bd..e86b1c4 100644 --- a/CryptoExchange.Net/Clients/RestApiClient.cs +++ b/CryptoExchange.Net/Clients/RestApiClient.cs @@ -271,7 +271,6 @@ namespace CryptoExchange.Net.Clients if (ClientOptions.UseUpdatedDeserialization) { result = await GetResponseAsync2(definition, request, definition.RateLimitGate, cancellationToken).ConfigureAwait(false); - } else { @@ -304,7 +303,7 @@ namespace CryptoExchange.Net.Clients } } - private async Task CheckTimeSync(int requestId, RequestDefinition definition) + private async ValueTask CheckTimeSync(int requestId, RequestDefinition definition) { if (!definition.Authenticated) return null; @@ -329,7 +328,7 @@ namespace CryptoExchange.Net.Clients /// /// Check rate limits for the request /// - protected virtual async Task RateLimitAsync( + protected virtual async ValueTask RateLimitAsync( string host, int requestId, RequestDefinition definition, @@ -626,7 +625,7 @@ namespace CryptoExchange.Net.Clients /// The result of the call /// The current try number /// True if call should retry, false if the call should return - protected virtual async Task ShouldRetryRequestAsync(IRateLimitGate? gate, WebCallResult callResult, int tries) + protected virtual async ValueTask ShouldRetryRequestAsync(IRateLimitGate? gate, WebCallResult callResult, int tries) { if (tries >= 2) // Only retry once @@ -708,7 +707,7 @@ namespace CryptoExchange.Net.Clients RequestFactory.UpdateSettings(options.Proxy, options.RequestTimeout ?? ClientOptions.RequestTimeout, ClientOptions.HttpKeepAliveInterval); } - internal async Task SyncTimeAsync() + internal async ValueTask SyncTimeAsync() { var timeSyncParams = GetTimeSyncInfo(); if (timeSyncParams == null) diff --git a/CryptoExchange.Net/RateLimiting/Interfaces/IRateLimitGate.cs b/CryptoExchange.Net/RateLimiting/Interfaces/IRateLimitGate.cs index eb38e6a..8d9b8dc 100644 --- a/CryptoExchange.Net/RateLimiting/Interfaces/IRateLimitGate.cs +++ b/CryptoExchange.Net/RateLimiting/Interfaces/IRateLimitGate.cs @@ -56,7 +56,7 @@ namespace CryptoExchange.Net.RateLimiting.Interfaces /// An additional optional suffix for the key selector. Can be used to make rate limiting work based on parameters. /// Cancelation token /// Error if RateLimitingBehaviour is Fail and rate limit is hit - Task ProcessAsync(ILogger logger, int itemId, RateLimitItemType type, RequestDefinition definition, string baseAddress, string? apiKey, int requestWeight, RateLimitingBehaviour behaviour, string? keySuffix, CancellationToken ct); + ValueTask ProcessAsync(ILogger logger, int itemId, RateLimitItemType type, RequestDefinition definition, string baseAddress, string? apiKey, int requestWeight, RateLimitingBehaviour behaviour, string? keySuffix, CancellationToken ct); /// /// Enforces the rate limit as defined in the request definition. When a rate limit is hit will wait for the rate limit to pass if RateLimitingBehaviour is Wait, or return an error if it is set to Fail @@ -73,6 +73,6 @@ namespace CryptoExchange.Net.RateLimiting.Interfaces /// An additional optional suffix for the key selector. Can be used to make rate limiting work based on parameters. /// Cancelation token /// Error if RateLimitingBehaviour is Fail and rate limit is hit - Task ProcessSingleAsync(ILogger logger, int itemId, IRateLimitGuard guard, RateLimitItemType type, RequestDefinition definition, string baseAddress, string? apiKey, int requestWeight, RateLimitingBehaviour behaviour, string? keySuffix, CancellationToken ct); + ValueTask ProcessSingleAsync(ILogger logger, int itemId, IRateLimitGuard guard, RateLimitItemType type, RequestDefinition definition, string baseAddress, string? apiKey, int requestWeight, RateLimitingBehaviour behaviour, string? keySuffix, CancellationToken ct); } } diff --git a/CryptoExchange.Net/RateLimiting/RateLimitGate.cs b/CryptoExchange.Net/RateLimiting/RateLimitGate.cs index c07c319..e37ff89 100644 --- a/CryptoExchange.Net/RateLimiting/RateLimitGate.cs +++ b/CryptoExchange.Net/RateLimiting/RateLimitGate.cs @@ -37,7 +37,7 @@ namespace CryptoExchange.Net.RateLimiting } /// - public async Task ProcessAsync(ILogger logger, int itemId, RateLimitItemType type, RequestDefinition definition, string host, string? apiKey, int requestWeight, RateLimitingBehaviour rateLimitingBehaviour, string? keySuffix, CancellationToken ct) + public async ValueTask ProcessAsync(ILogger logger, int itemId, RateLimitItemType type, RequestDefinition definition, string host, string? apiKey, int requestWeight, RateLimitingBehaviour rateLimitingBehaviour, string? keySuffix, CancellationToken ct) { await _semaphore.WaitAsync(ct).ConfigureAwait(false); bool release = true; @@ -61,7 +61,7 @@ namespace CryptoExchange.Net.RateLimiting } /// - public async Task ProcessSingleAsync( + public async ValueTask ProcessSingleAsync( ILogger logger, int itemId, IRateLimitGuard guard, @@ -95,7 +95,7 @@ namespace CryptoExchange.Net.RateLimiting } } - private async Task CheckGuardsAsync(IEnumerable guards, ILogger logger, int itemId, RateLimitItemType type, RequestDefinition definition, string host, string? apiKey, int requestWeight, RateLimitingBehaviour rateLimitingBehaviour, string? keySuffix, CancellationToken ct) + private async ValueTask CheckGuardsAsync(IEnumerable guards, ILogger logger, int itemId, RateLimitItemType type, RequestDefinition definition, string host, string? apiKey, int requestWeight, RateLimitingBehaviour rateLimitingBehaviour, string? keySuffix, CancellationToken ct) { foreach (var guard in guards) {