|
|
@@ -80,6 +80,8 @@ namespace ET
|
|
|
|
|
|
public struct ETAsyncTaskMethodBuilder<T>
|
|
|
{
|
|
|
+ private IStateMachineWrap iStateMachineWrap;
|
|
|
+
|
|
|
private ETTask<T> tcs;
|
|
|
|
|
|
// 1. Static Create method.
|
|
|
@@ -98,6 +100,11 @@ namespace ET
|
|
|
[DebuggerHidden]
|
|
|
public void SetException(Exception exception)
|
|
|
{
|
|
|
+ if (this.iStateMachineWrap != null)
|
|
|
+ {
|
|
|
+ this.iStateMachineWrap.Recycle();
|
|
|
+ this.iStateMachineWrap = null;
|
|
|
+ }
|
|
|
this.tcs.SetException(exception);
|
|
|
}
|
|
|
|
|
|
@@ -105,6 +112,11 @@ namespace ET
|
|
|
[DebuggerHidden]
|
|
|
public void SetResult(T ret)
|
|
|
{
|
|
|
+ if (this.iStateMachineWrap != null)
|
|
|
+ {
|
|
|
+ this.iStateMachineWrap.Recycle();
|
|
|
+ this.iStateMachineWrap = null;
|
|
|
+ }
|
|
|
this.tcs.SetResult(ret);
|
|
|
}
|
|
|
|
|
|
@@ -112,7 +124,8 @@ namespace ET
|
|
|
[DebuggerHidden]
|
|
|
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
|
|
|
{
|
|
|
- awaiter.OnCompleted(stateMachine.MoveNext);
|
|
|
+ this.iStateMachineWrap ??= StateMachineWrap<TStateMachine>.Fetch(ref stateMachine);
|
|
|
+ awaiter.OnCompleted(this.iStateMachineWrap.MoveNext);
|
|
|
}
|
|
|
|
|
|
// 6. AwaitUnsafeOnCompleted
|
|
|
@@ -120,7 +133,8 @@ namespace ET
|
|
|
[SecuritySafeCritical]
|
|
|
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
|
|
|
{
|
|
|
- awaiter.OnCompleted(stateMachine.MoveNext);
|
|
|
+ this.iStateMachineWrap ??= StateMachineWrap<TStateMachine>.Fetch(ref stateMachine);
|
|
|
+ awaiter.UnsafeOnCompleted(this.iStateMachineWrap.MoveNext);
|
|
|
}
|
|
|
|
|
|
// 7. Start
|