private ValueAwaiter <T> GetAwaiterCore()
        {
            lock (SyncObj)
            {
                // Now that we hold the lock, try reading again.
                T item;
                if (TryRead(out item))
                {
                    return(new ValueAwaiter <T>(item));
                }

                // If no more items will be written, fail the read.
                if (_doneWriting != null)
                {
                    return(new ValueAwaiter <T>(ChannelUtilities.GetInvalidCompletionValueTask <T>(_doneWriting)));
                }

                Debug.Assert(_blockedReader == null || ((_blockedReader as ReaderInteractor <T>)?.Task.IsCanceled ?? false),
                             "Incorrect usage; multiple outstanding reads were issued against this single-consumer channel");

                // Store the reader to be completed by a writer.
                _blockedReader = _awaiter ?? (_awaiter = new AutoResetAwaiter <T>(_runContinuationsAsynchronously));
                return(new ValueAwaiter <T>(_awaiter));
            }
        }
Example #2
0
        public void Ctor_Succeeds(bool runContinuationsAsynchronously)
        {
            var ara = new AutoResetAwaiter <int>(runContinuationsAsynchronously);

            Assert.False(ara.IsCompleted);
        }