1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-19 20:33:03 +00:00

Added support for requiring multiple responses for queries, fixed possible exception when closing connection, added ToString override DataEvent object

This commit is contained in:
JKorf
2024-07-16 15:23:09 +02:00
parent 17d85fdd85
commit a85bfb4432
11 changed files with 50 additions and 12 deletions
+30 -7
View File
@@ -24,6 +24,17 @@ namespace CryptoExchange.Net.Sockets
/// </summary>
public bool Completed { get; set; }
/// <summary>
/// The number of required responses. Can be more than 1 when for example subscribing multiple symbols streams in a single request,
/// and each symbol receives it's own confirmation response
/// </summary>
public int RequiredResponses { get; set; } = 1;
/// <summary>
/// The current number of responses received on this query
/// </summary>
public int CurrentResponses { get; set; }
/// <summary>
/// Timestamp of when the request was send
/// </summary>
@@ -108,7 +119,7 @@ namespace CryptoExchange.Net.Sockets
}
/// <summary>
/// Wait untill timeout or the request is competed
/// Wait until timeout or the request is completed
/// </summary>
/// <param name="timeout"></param>
/// <param name="ct">Cancellation token</param>
@@ -167,12 +178,24 @@ namespace CryptoExchange.Net.Sockets
/// <inheritdoc />
public override async Task<CallResult> Handle(SocketConnection connection, DataEvent<object> message)
{
Completed = true;
Response = message.Data;
Result = HandleMessage(connection, message.As((TServerResponse)message.Data));
_event.Set();
if (ContinueAwaiter != null)
await ContinueAwaiter.WaitAsync().ConfigureAwait(false);
CurrentResponses++;
if (CurrentResponses == RequiredResponses)
{
Completed = true;
Response = message.Data;
}
if (Result?.Success != false)
// If an error result is already set don't override that
Result = HandleMessage(connection, message.As((TServerResponse)message.Data));
if (CurrentResponses == RequiredResponses)
{
_event.Set();
if (ContinueAwaiter != null)
await ContinueAwaiter.WaitAsync().ConfigureAwait(false);
}
return Result;
}