コード例 #1
0
        public void set_enqueue_signal()
        {
            var awaiter = new QueueAwaiter();

            awaiter.SetDequeueSignal();

            Assert.True(awaiter.IsDequeueSignalSet);
        }
コード例 #2
0
        public async Task await_dequeue_signal_until_set_then_reset_signal()
        {
            var cts     = new CancellationTokenSource(5000);
            var awaiter = new QueueAwaiter();

            var waitTask = awaiter.AwaitDequeueSignalAsync();

            Assert.False(awaiter.IsDequeueSignalSet);

            awaiter.SetDequeueSignal();

            await Task.WhenAny(new[] { waitTask, cts.Token.WaitHandle.AsTask() });

            if (cts.IsCancellationRequested)
            {
                throw new TimeoutException();
            }

            // Signal should auto reset.
            Assert.False(awaiter.IsDequeueSignalSet);
        }