Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
YieldAwaitable.cs
Go to the documentation of this file.
5
7
8[StructLayout(LayoutKind.Sequential, Size = 1)]
9public readonly struct YieldAwaitable
10{
11 [StructLayout(LayoutKind.Sequential, Size = 1)]
13 {
14 private static readonly WaitCallback s_waitCallbackRunAction = RunAction;
15
16 private static readonly SendOrPostCallback s_sendOrPostCallbackRunAction = RunAction;
17
18 public bool IsCompleted => false;
19
20 public void OnCompleted(Action continuation)
21 {
22 QueueContinuation(continuation, flowContext: true);
23 }
24
25 public void UnsafeOnCompleted(Action continuation)
26 {
27 QueueContinuation(continuation, flowContext: false);
28 }
29
30 private static void QueueContinuation(Action continuation, bool flowContext)
31 {
32 if (continuation == null)
33 {
34 throw new ArgumentNullException("continuation");
35 }
36 if (TplEventSource.Log.IsEnabled())
37 {
38 continuation = OutputCorrelationEtwEvent(continuation);
39 }
41 if (current != null && current.GetType() != typeof(SynchronizationContext))
42 {
43 current.Post(s_sendOrPostCallbackRunAction, continuation);
44 return;
45 }
47 if (current2 == TaskScheduler.Default)
48 {
49 if (flowContext)
50 {
52 }
53 else
54 {
56 }
57 }
58 else
59 {
60 Task.Factory.StartNew(continuation, default(CancellationToken), TaskCreationOptions.PreferFairness, current2);
61 }
62 }
63
65 {
66 if (TplEventSource.Log.IsEnabled())
67 {
68 QueueContinuation(box.MoveNextAction, flowContext: false);
69 return;
70 }
72 if (current != null && current.GetType() != typeof(SynchronizationContext))
73 {
74 current.Post(delegate(object s)
75 {
76 ((IAsyncStateMachineBox)s).MoveNext();
77 }, box);
78 return;
79 }
81 if (current2 == TaskScheduler.Default)
82 {
83 ThreadPool.UnsafeQueueUserWorkItemInternal(box, preferLocal: false);
84 return;
85 }
86 Task.Factory.StartNew(delegate(object s)
87 {
88 ((IAsyncStateMachineBox)s).MoveNext();
89 }, box, default(CancellationToken), TaskCreationOptions.PreferFairness, current2);
90 }
91
92 private static Action OutputCorrelationEtwEvent(Action continuation)
93 {
94 int num = Task.NewId();
95 Task internalCurrent = Task.InternalCurrent;
96 TplEventSource.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, internalCurrent?.Id ?? 0, num);
97 return AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, delegate(Action innerContinuation, Task continuationIdTask)
98 {
100 log.TaskWaitContinuationStarted(((Task<int>)continuationIdTask).Result);
101 Guid oldActivityThatWillContinue = default(Guid);
102 if (log.TasksSetActivityIds)
103 {
104 EventSource.SetCurrentThreadActivityId(TplEventSource.CreateGuidForTaskID(((Task<int>)continuationIdTask).Result), out oldActivityThatWillContinue);
105 }
106 innerContinuation();
107 if (log.TasksSetActivityIds)
108 {
109 EventSource.SetCurrentThreadActivityId(oldActivityThatWillContinue);
110 }
111 log.TaskWaitContinuationComplete(((Task<int>)continuationIdTask).Result);
112 }, Task.FromResult(num));
113 }
114
115 private static void RunAction(object state)
116 {
117 ((Action)state)();
118 }
119
120 public void GetResult()
121 {
122 }
123 }
124
126 {
127 return default(YieldAwaiter);
128 }
129}
static Action CreateContinuationWrapper(Action continuation, Action< Action, Task > invokeAction, Task innerTask)
virtual void Post(SendOrPostCallback d, object? state)
static ? SynchronizationContext Current
static new TaskFactory< TResult > Factory
Definition Task.cs:56
static ? Task InternalCurrent
Definition Task.cs:1011
static readonly TplEventSource Log
static bool QueueUserWorkItem(WaitCallback callBack)
static bool UnsafeQueueUserWorkItem(WaitCallback callBack, object? state)
static void UnsafeQueueUserWorkItemInternal(object callBack, bool preferLocal)
delegate void Action()
static readonly SendOrPostCallback s_sendOrPostCallbackRunAction
static Action OutputCorrelationEtwEvent(Action continuation)
static void QueueContinuation(Action continuation, bool flowContext)