Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ WaitToReadAsync()

override ValueTask< bool > System.Threading.Channels.BoundedChannel< T >.BoundedChannelReader.WaitToReadAsync ( CancellationToken cancellationToken)
inline

Definition at line 111 of file BoundedChannel.cs.

112 {
113 if (cancellationToken.IsCancellationRequested)
114 {
116 }
117 BoundedChannel<T> parent = _parent;
118 lock (parent.SyncObj)
119 {
120 if (!parent._items.IsEmpty)
121 {
122 return new ValueTask<bool>(result: true);
123 }
124 if (parent._doneWriting != null)
125 {
126 return (parent._doneWriting != ChannelUtilities.s_doneWritingSentinel) ? new ValueTask<bool>(Task.FromException<bool>(parent._doneWriting)) : default(ValueTask<bool>);
127 }
128 if (!cancellationToken.CanBeCanceled)
129 {
131 if (waiterSingleton.TryOwnAndReset())
132 {
133 ChannelUtilities.QueueWaiter(ref parent._waitingReadersTail, waiterSingleton);
134 return waiterSingleton.ValueTaskOfT;
135 }
136 }
137 AsyncOperation<bool> asyncOperation = new AsyncOperation<bool>(parent._runContinuationsAsynchronously | cancellationToken.CanBeCanceled, cancellationToken);
138 ChannelUtilities.QueueWaiter(ref _parent._waitingReadersTail, asyncOperation);
139 return asyncOperation.ValueTaskOfT;
140 }
141 }
static Task FromException(Exception exception)
Definition Task.cs:3341
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363

References System.Threading.Channels.BoundedChannel< T >.BoundedChannelReader._parent, System.Threading.Channels.BoundedChannel< T >.BoundedChannelReader._waiterSingleton, System.cancellationToken, System.Threading.Tasks.Task< TResult >.FromCanceled(), System.Threading.Tasks.Task< TResult >.FromException(), System.Threading.Channels.ChannelUtilities.QueueWaiter(), and System.Threading.Channels.ChannelUtilities.s_doneWritingSentinel.