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

◆ WaitToReadAsync()

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

Definition at line 97 of file SingleConsumerUnboundedChannel.cs.

98 {
99 if (cancellationToken.IsCancellationRequested)
100 {
102 }
103 if (!_parent._items.IsEmpty)
104 {
105 return new ValueTask<bool>(result: true);
106 }
110 lock (parent.SyncObj)
111 {
112 if (!parent._items.IsEmpty)
113 {
114 return new ValueTask<bool>(result: true);
115 }
116 if (parent._doneWriting != null)
117 {
118 return (parent._doneWriting != ChannelUtilities.s_doneWritingSentinel) ? new ValueTask<bool>(Task.FromException<bool>(parent._doneWriting)) : default(ValueTask<bool>);
119 }
120 asyncOperation = parent._waitingReader;
121 if (!cancellationToken.CanBeCanceled && _waiterSingleton.TryOwnAndReset())
122 {
125 {
126 asyncOperation = null;
127 }
128 }
129 else
130 {
131 asyncOperation2 = new AsyncOperation<bool>(_parent._runContinuationsAsynchronously, cancellationToken);
132 }
133 parent._waitingReader = asyncOperation2;
134 }
135 asyncOperation?.TrySetCanceled();
136 return asyncOperation2.ValueTaskOfT;
137 }
static Task FromException(Exception exception)
Definition Task.cs:3341
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363

References System.Threading.Channels.SingleConsumerUnboundedChannel< T >.UnboundedChannelReader._parent, System.Threading.Channels.SingleConsumerUnboundedChannel< T >.UnboundedChannelReader._waiterSingleton, System.cancellationToken, System.Threading.Tasks.Task< TResult >.FromCanceled(), System.Threading.Tasks.Task< TResult >.FromException(), System.Threading.Channels.ChannelUtilities.s_doneWritingSentinel, and System.Threading.Channels.AsyncOperation< TResult >.TryOwnAndReset().