mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-09 21:24:34 +00:00
Use recommended async dispose pattern
Funny enough, non-breaking API changes since all of those classes are sealed.
This commit is contained in:
@@ -29,7 +29,7 @@ using ArchiSteamFarm.Core;
|
||||
|
||||
namespace ArchiSteamFarm.Helpers;
|
||||
|
||||
internal sealed class CrossProcessFileBasedSemaphore : ICrossProcessSemaphore, IDisposable {
|
||||
internal sealed class CrossProcessFileBasedSemaphore : IAsyncDisposable, ICrossProcessSemaphore, IDisposable {
|
||||
private const ushort SpinLockDelay = 1000; // In milliseconds
|
||||
|
||||
private readonly string FilePath;
|
||||
@@ -48,11 +48,23 @@ internal sealed class CrossProcessFileBasedSemaphore : ICrossProcessSemaphore, I
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
// Those are objects that are always being created if constructor doesn't throw exception
|
||||
LocalSemaphore.Dispose();
|
||||
|
||||
// Those are objects that might be null and the check should be in-place
|
||||
FileLock?.Dispose();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync() {
|
||||
// Those are objects that are always being created if constructor doesn't throw exception
|
||||
LocalSemaphore.Dispose();
|
||||
|
||||
// Those are objects that might be null and the check should be in-place
|
||||
if (FileLock != null) {
|
||||
await FileLock.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ICrossProcessSemaphore.Release() {
|
||||
// ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that
|
||||
lock (LocalSemaphore) {
|
||||
|
||||
Reference in New Issue
Block a user