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

◆ WaitToReadAsync()

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

Definition at line 101 of file UnboundedChannel.cs.

102 {
103 if (cancellationToken.IsCancellationRequested)
104 {
106 }
107 if (!_parent._items.IsEmpty)
108 {
109 return new ValueTask<bool>(result: true);
110 }
112 lock (parent.SyncObj)
113 {
114 if (!parent._items.IsEmpty)
115 {
116 return new ValueTask<bool>(result: true);
117 }
118 if (parent._doneWriting != null)
119 {
120 return (parent._doneWriting != ChannelUtilities.s_doneWritingSentinel) ? new ValueTask<bool>(Task.FromException<bool>(parent._doneWriting)) : default(ValueTask<bool>);
121 }
122 if (!cancellationToken.CanBeCanceled)
123 {
125 if (waiterSingleton.TryOwnAndReset())
126 {
127 ChannelUtilities.QueueWaiter(ref parent._waitingReadersTail, waiterSingleton);
128 return waiterSingleton.ValueTaskOfT;
129 }
130 }
131 AsyncOperation<bool> asyncOperation = new AsyncOperation<bool>(parent._runContinuationsAsynchronously, cancellationToken);
132 ChannelUtilities.QueueWaiter(ref parent._waitingReadersTail, asyncOperation);
133 return asyncOperation.ValueTaskOfT;
134 }
135 }
static Task FromException(Exception exception)
Definition Task.cs:3341
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363

References System.Threading.Channels.UnboundedChannel< T >.UnboundedChannelReader._parent, System.Threading.Channels.UnboundedChannel< T >.UnboundedChannelReader._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.