This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (!cancellationToken.CanBeCanceled) | |
| { | |
| AsyncOperation<T> singleton = _readerSingleton; | |
| if (singleton.TryOwnAndReset()) | |
| { | |
| parent._blockedReaders.EnqueueTail(singleton); | |
| return singleton.ValueTaskOfT; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (parent._doneWriting != null) | |
| { | |
| return ChannelUtilities.GetInvalidCompletionValueTask<T>(parent._doneWriting); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lock (parent.SyncObj) | |
| { | |
| parent.AssertInvariants(); | |
| // Try to dequeue again, now that we hold the lock. | |
| if (parent._items.TryDequeue(out item)) | |
| { | |
| CompleteIfDone(parent); | |
| return new ValueTask<T>(item); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void CompleteIfDone(UnboundedChannel<T> parent) | |
| { | |
| if (parent._doneWriting != null && parent._items.IsEmpty) | |
| { | |
| // If we've now emptied the items queue and we're not getting any more, complete. | |
| ChannelUtilities.Complete(parent._completion, parent._doneWriting); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UnboundedChannel<T> parent = _parent; | |
| if (parent._items.TryDequeue(out T item)) | |
| { | |
| CompleteIfDone(parent); | |
| return new ValueTask<T>(item); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (cancellationToken.IsCancellationRequested) | |
| { | |
| return new ValueTask<T>(Task.FromCanceled<T>(cancellationToken)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal UnboundedChannelReader(UnboundedChannel<T> parent) | |
| { | |
| _parent = parent; | |
| _readerSingleton = new AsyncOperation<T>(parent._runContinuationsAsynchronously, pooled: true); | |
| _waiterSingleton = new AsyncOperation<bool>(parent._runContinuationsAsynchronously, pooled: true); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (blockedReader != null) | |
| { | |
| // Complete the reader. It's possible the reader was canceled, in which | |
| // case we loop around to try everything again. | |
| if (blockedReader.TrySetResult(item)) | |
| { | |
| return true; | |
| } | |
| } | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Complete(Exception? error = null) | |
| { | |
| if (!TryComplete(error)) | |
| { | |
| throw ChannelUtilities.CreateInvalidCompletionException(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ChannelUtilities.FailOperations<AsyncOperation<T>, T>(parent._blockedReaders, ChannelUtilities.CreateInvalidCompletionException(error)); | |
| ChannelUtilities.WakeUpWaiters(ref parent._waitingReadersTail, result: false, error: error); | |
| return true; |