Esempio n. 1
0
        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)
            {
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public async Task Dispose()
        {               //****************************************
            var Lock = new AsyncKeyedLock <int>();
            //****************************************

            await Lock.DisposeAsync();
        }
Esempio n. 4
0
        public async Task LockDispose()
        {               //****************************************
            var       Lock = new AsyncKeyedLock <int>();
            ValueTask MyDisposeTask;

            //****************************************

            using (await Lock.Lock(42))
            {
                MyDisposeTask = Lock.DisposeAsync();
            }

            await MyDisposeTask;
        }
Esempio n. 5
0
        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)
            {
            }
        }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
        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;
        }