public async Task LockLockDispose() { //**************************************** var Lock = new AsyncKeyedLock <int>(); ValueTask MyDisposeTask; ValueTask <AsyncKeyedLock <int> .Instance> MyInnerTask; //**************************************** using (await Lock.Lock(42)) { MyInnerTask = Lock.Lock(42); MyDisposeTask = Lock.DisposeAsync(); } await MyDisposeTask; //**************************************** try { (await MyInnerTask).Dispose(); Assert.Fail("Should never reach this point"); } catch (ObjectDisposedException) { } }
public async Task ConcurrentMany() { //**************************************** var Lock = new AsyncKeyedLock <int>(); //**************************************** using (var MySource = new CancellationTokenSource()) { var WorkTask1 = ConcurrentLockRelease(Lock, 42, 0, MySource.Token); var WorkTask2 = ConcurrentLockRelease(Lock, 42, 1, MySource.Token); var WorkTask3 = ConcurrentLockRelease(Lock, 42, 2, MySource.Token); await Task.Delay(500); MySource.Cancel(); await WorkTask1; await WorkTask2; await WorkTask3; } await Lock.DisposeAsync(); //**************************************** CollectionAssert.IsEmpty(Lock.KeysHeld); }
public async Task Dispose() { //**************************************** var Lock = new AsyncKeyedLock <int>(); //**************************************** await Lock.DisposeAsync(); }
public async Task LockDispose() { //**************************************** var Lock = new AsyncKeyedLock <int>(); ValueTask MyDisposeTask; //**************************************** using (await Lock.Lock(42)) { MyDisposeTask = Lock.DisposeAsync(); } await MyDisposeTask; }
public async Task DisposeLock() { //**************************************** var Lock = new AsyncKeyedLock <int>(); //**************************************** await Lock.DisposeAsync(); try { await Lock.Lock(42); Assert.Fail("Should never reach this point"); } catch (ObjectDisposedException) { } }
public async Task ConcurrentDispose() { //**************************************** var Lock = new AsyncKeyedLock <int>(); ValueTask MyDisposeTask; //**************************************** var WorkTask = ConcurrentLockRelease(Lock, 42, 0, CancellationToken.None); await Task.Delay(50); MyDisposeTask = Lock.DisposeAsync(); try { await WorkTask; Assert.Fail("Should not reach this point"); } catch (ObjectDisposedException) { } await MyDisposeTask; }
public async Task LockDisposeLock() { //**************************************** var Lock = new AsyncKeyedLock <int>(); ValueTask MyDisposeTask; //**************************************** using (await Lock.Lock(42)) { MyDisposeTask = Lock.DisposeAsync(); try { await Lock.Lock(42); Assert.Fail("Should never reach this point"); } catch (ObjectDisposedException) { } } await MyDisposeTask; }