File tree Expand file tree Collapse file tree 4 files changed +11
-11
lines changed
Expand file tree Collapse file tree 4 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,6 @@ public AsyncLock()
2222 }
2323
2424 internal AsyncLock ( object syncObject )
25- : this ( )
2625 {
2726 _syncObj = syncObject ;
2827 }
Original file line number Diff line number Diff line change @@ -16,15 +16,15 @@ namespace ImageWizard.Core.Locking;
1616public class AsyncLockReleaser : IDisposable
1717{
1818 private readonly AsyncLock _asyncLock ;
19- private readonly AsyncLockType ? _type ;
19+ private readonly AsyncLockType _type ;
2020
21- internal AsyncLockReleaser ( AsyncLock asyncLock , AsyncLockType ? type )
21+ internal AsyncLockReleaser ( AsyncLock asyncLock , AsyncLockType type )
2222 {
2323 _asyncLock = asyncLock ;
2424 _type = type ;
2525 }
2626
27- internal AsyncLockType ? Type => _type ;
27+ internal AsyncLockType Type => _type ;
2828
2929 internal AsyncLock AsyncLock => _asyncLock ;
3030
@@ -37,11 +37,10 @@ public void Dispose()
3737 return ;
3838 }
3939
40- if ( _type != null )
41- {
42- _asyncLock . Release ( _type . Value ) ;
43- }
44-
40+ _asyncLock . Release ( _type ) ;
41+
4542 _disposed = true ;
43+
44+ GC . SuppressFinalize ( this ) ;
4645 }
4746}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public static class QueueExtensions
1515{
1616 public static TaskCompletionSource < T > Enqueue < T > ( this Queue < TaskCompletionSource < T > > queue , CancellationToken cancellationToken )
1717 {
18- TaskCompletionSource < T > item = new TaskCompletionSource < T > ( ) ;
18+ TaskCompletionSource < T > item = new TaskCompletionSource < T > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
1919
2020 queue . Enqueue ( item ) ;
2121
Original file line number Diff line number Diff line change @@ -48,7 +48,9 @@ public async Task WriterReaderSameKey()
4848 {
4949 AsyncLock < string > lockEntity = new AsyncLock < string > ( ) ;
5050
51- using var w1 = await lockEntity . WriterLockAsync ( "2" ) ;
51+ CancellationTokenSource s = new CancellationTokenSource ( ) ;
52+
53+ using var w1 = await lockEntity . WriterLockAsync ( "2" , s . Token ) ;
5254
5355 await Assert . ThrowsAsync < TimeoutException > ( ( ) => lockEntity . ReaderLockAsync ( "2" ) . WaitAsync ( TimeSpan . FromSeconds ( 1 ) ) ) ;
5456 }
You can’t perform that action at this time.
0 commit comments