コード例 #1
0
        public async Task IsolatedRequestsWaitForPrecedingReentrantsToClearOff()
        {
            var exceptions = new ExceptionSink();
            var requests   = new RequestRunner(TaskScheduler.Default, exceptions);

            long callCount = 0;

            requests.PerformAndForget(async() => {
                Interlocked.Increment(ref callCount);
                await Task.Delay(100);
                Interlocked.Decrement(ref callCount);
            }, RequestMode.Reentrant);

            await Task.Delay(15);

            bool clashed = await requests.Perform(() => {
                var c = Interlocked.Read(ref callCount);
                return(Task.FromResult(c > 0));
            }, RequestMode.Isolated);

            await requests.WhenIdle();

            exceptions.RethrowAll();

            Assert.That(clashed, Is.False);
        }
コード例 #2
0
        public async Task Closing_Performed()
        {
            var exceptions = new ExceptionSink();
            var requests   = new RequestRunner(TaskScheduler.Default, exceptions);

            bool closed = false;

            requests.PerformAndForget(() => Task.Delay(50));

            requests.Close(() => {
                closed = true;
                return(Task.CompletedTask);
            });

            await requests.WhenIdle();

            exceptions.RethrowAll();

            Assert.That(closed, Is.True);
        }