1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-18 11:52:54 +00:00

Added custom async wait event implementation as the previously used method seemed to not work 100% of the time

This commit is contained in:
Jkorf
2021-10-05 14:31:27 +02:00
parent 4ef20a9637
commit f3102a4dad
7 changed files with 282 additions and 229 deletions
@@ -29,7 +29,7 @@ namespace CryptoExchange.Net.Sockets
private Task? _sendTask;
private Task? _receiveTask;
private Task? _timeoutTask;
private readonly AutoResetEvent _sendEvent;
private readonly AsyncResetEvent _sendEvent;
private readonly ConcurrentQueue<byte[]> _sendBuffer;
private readonly IDictionary<string, string> cookies;
private readonly IDictionary<string, string> headers;
@@ -216,7 +216,7 @@ namespace CryptoExchange.Net.Sockets
_outgoingMessages = new List<DateTime>();
_receivedMessages = new Dictionary<DateTime, int>();
_sendEvent = new AutoResetEvent(false);
_sendEvent = new AsyncResetEvent();
_sendBuffer = new ConcurrentQueue<byte[]>();
_ctsSource = new CancellationTokenSource();
_receivedMessagesLock = new object();
@@ -385,7 +385,7 @@ namespace CryptoExchange.Net.Sockets
if (_closing)
break;
await _sendEvent.WaitOneAsync().ConfigureAwait(false);
await _sendEvent.WaitAsync().ConfigureAwait(false);
if (_closing)
break;
@@ -282,7 +282,7 @@ namespace CryptoExchange.Net.Sockets
pendingRequests.Add(pending);
}
Send(obj);
return pending.Event.WaitOneAsync(timeout);
return pending.Event.WaitAsync(timeout);
}
/// <summary>
@@ -525,7 +525,7 @@ namespace CryptoExchange.Net.Sockets
{
public Func<JToken, bool> Handler { get; }
public JToken? Result { get; private set; }
public ManualResetEvent Event { get; }
public AsyncResetEvent Event { get; }
public TimeSpan Timeout { get; }
private readonly DateTime startTime;
@@ -533,7 +533,7 @@ namespace CryptoExchange.Net.Sockets
public PendingRequest(Func<JToken, bool> handler, TimeSpan timeout)
{
Handler = handler;
Event = new ManualResetEvent(false);
Event = new AsyncResetEvent(false, false);
Timeout = timeout;
startTime = DateTime.UtcNow;
}