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

◆ ReadAsync()

override ValueTask< T > System.Threading.Channels.UnboundedChannel< T >.UnboundedChannelReader.ReadAsync ( CancellationToken cancellationToken)
inlinevirtual

Reimplemented from System.Threading.Channels.ChannelReader< T >.

Definition at line 38 of file UnboundedChannel.cs.

39 {
40 if (cancellationToken.IsCancellationRequested)
41 {
43 }
45 if (parent._items.TryDequeue(out var result))
46 {
47 CompleteIfDone(parent);
48 return new ValueTask<T>(result);
49 }
50 lock (parent.SyncObj)
51 {
52 if (parent._items.TryDequeue(out result))
53 {
54 CompleteIfDone(parent);
55 return new ValueTask<T>(result);
56 }
57 if (parent._doneWriting != null)
58 {
59 return ChannelUtilities.GetInvalidCompletionValueTask<T>(parent._doneWriting);
60 }
61 if (!cancellationToken.CanBeCanceled)
62 {
64 if (readerSingleton.TryOwnAndReset())
65 {
66 parent._blockedReaders.EnqueueTail(readerSingleton);
67 return readerSingleton.ValueTaskOfT;
68 }
69 }
70 AsyncOperation<T> asyncOperation = new AsyncOperation<T>(parent._runContinuationsAsynchronously, cancellationToken);
71 parent._blockedReaders.EnqueueTail(asyncOperation);
72 return asyncOperation.ValueTaskOfT;
73 }
74 }
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363

References System.Threading.Channels.UnboundedChannel< T >.UnboundedChannelReader._parent, System.Threading.Channels.UnboundedChannel< T >.UnboundedChannelReader._readerSingleton, System.cancellationToken, System.Threading.Channels.UnboundedChannel< T >.UnboundedChannelReader.CompleteIfDone(), and System.Threading.Tasks.Task< TResult >.FromCanceled().