feature: Implement Dispose for types which have disposable data (#1171)
* Initial set of dispose implementations Not handled yet: - Discord.Net.Websocket/Entities/SocketGuild - Discord.Net.Tests * Refactor DiscordSocketClient init into ctor This way we remove an IDisposableAnalyzer warning for not disposing the client when we set the client variable. * Dispose of clients when disposing sharded client * Finish implementing IDisposable where appropriate I opted to use NoWarn in the Tests project as it wasn't really necessary considering that our tests only run once * Tweak samples after feedback
This commit is contained in:
@@ -43,7 +43,10 @@ namespace Discord.Net
|
||||
if (!_isDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_blobCache.Dispose();
|
||||
_cancelTokenSource?.Dispose();
|
||||
}
|
||||
_isDisposed = true;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +73,7 @@ namespace Discord.Net
|
||||
{
|
||||
if (method != "GET")
|
||||
throw new InvalidOperationException("This RestClient only supports GET requests.");
|
||||
|
||||
|
||||
string uri = Path.Combine(_baseUrl, endpoint);
|
||||
var bytes = await _blobCache.DownloadUrl(uri, _headers);
|
||||
return new RestResponse(HttpStatusCode.OK, _headers, new MemoryStream(bytes));
|
||||
@@ -84,7 +87,7 @@ namespace Discord.Net
|
||||
throw new InvalidOperationException("This RestClient does not support multipart requests.");
|
||||
}
|
||||
|
||||
public async Task ClearAsync()
|
||||
public async Task ClearAsync()
|
||||
{
|
||||
await _blobCache.InvalidateAll();
|
||||
}
|
||||
@@ -93,7 +96,7 @@ namespace Discord.Net
|
||||
{
|
||||
if (Info != null)
|
||||
return;
|
||||
|
||||
|
||||
bool needsReset = false;
|
||||
try
|
||||
{
|
||||
@@ -117,4 +120,4 @@ namespace Discord.Net
|
||||
await _blobCache.InsertObject<CacheInfo>("info", Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user