mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
Dispose handling order book
This commit is contained in:
parent
c22b54c898
commit
5c99da6617
@ -152,6 +152,9 @@ namespace CryptoExchange.Net
|
||||
/// <returns></returns>
|
||||
protected virtual async Task<CallResult<UpdateSubscription>> SubscribeAsync<T>(SocketApiClient apiClient, string url, object? request, string? identifier, bool authenticated, Action<DataEvent<T>> dataHandler, CancellationToken ct)
|
||||
{
|
||||
if (disposing)
|
||||
return new CallResult<UpdateSubscription>(new InvalidOperationError("Client disposed, can't subscribe"));
|
||||
|
||||
SocketConnection socketConnection;
|
||||
SocketSubscription subscription;
|
||||
var released = false;
|
||||
@ -277,6 +280,9 @@ namespace CryptoExchange.Net
|
||||
/// <returns></returns>
|
||||
protected virtual async Task<CallResult<T>> QueryAsync<T>(SocketApiClient apiClient, string url, object request, bool authenticated)
|
||||
{
|
||||
if (disposing)
|
||||
return new CallResult<T>(new InvalidOperationError("Client disposed, can't query"));
|
||||
|
||||
SocketConnection socketConnection;
|
||||
var released = false;
|
||||
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||
|
@ -69,7 +69,15 @@
|
||||
/// <summary>
|
||||
/// Data synced, order book is up to date
|
||||
/// </summary>
|
||||
Synced
|
||||
Synced,
|
||||
/// <summary>
|
||||
/// Disposing
|
||||
/// </summary>
|
||||
Disposing,
|
||||
/// <summary>
|
||||
/// Disposed
|
||||
/// </summary>
|
||||
Disposed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -506,9 +506,36 @@ namespace CryptoExchange.Net.OrderBook
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose the order book
|
||||
/// IDisposable implementation for the order book
|
||||
/// </summary>
|
||||
public abstract void Dispose();
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose method
|
||||
/// </summary>
|
||||
/// <param name="disposing"></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
Status = OrderBookStatus.Disposing;
|
||||
|
||||
_cts?.Cancel();
|
||||
_queueEvent.Set();
|
||||
|
||||
// Clear queue
|
||||
while (_processQueue.TryDequeue(out _)) { }
|
||||
|
||||
processBuffer.Clear();
|
||||
asks.Clear();
|
||||
bids.Clear();
|
||||
AskCount = 0;
|
||||
BidCount = 0;
|
||||
|
||||
Status = OrderBookStatus.Disposed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// String representation of the top 3 entries
|
||||
|
Loading…
x
Reference in New Issue
Block a user