2 using System
.Threading
.Tasks
;
3 using System
.Runtime
.CompilerServices
;
5 [AsyncMethodBuilder (typeof(MyTaskMethodBuilder
<>))]
10 [AsyncMethodBuilder (typeof(MyTaskMethodBuilder
))]
15 class MyTaskMethodBuilder
17 public static MyTaskMethodBuilder
Create()
28 public void SetException (Exception exception
)
33 public void SetResult ()
38 public void AwaitOnCompleted
<TAwaiter
, TStateMachine
> (ref TAwaiter awaiter
, ref TStateMachine stateMachine
) where TAwaiter
: INotifyCompletion where TStateMachine
: IAsyncStateMachine
43 public void AwaitUnsafeOnCompleted
<TAwaiter
, TStateMachine
> (ref TAwaiter awaiter
, ref TStateMachine stateMachine
) where TAwaiter
: ICriticalNotifyCompletion where TStateMachine
: IAsyncStateMachine
48 public void Start
<TStateMachine
> (ref TStateMachine stateMachine
) where TStateMachine
: IAsyncStateMachine
53 public void SetStateMachine (IAsyncStateMachine stateMachine
)
59 class MyTaskMethodBuilder
<T
>
61 public static MyTaskMethodBuilder
<T
> Create()
66 public MyTask
<T
> Task
{
72 public void SetException (Exception exception
)
77 public void SetResult (T result
)
82 public void AwaitOnCompleted
<TAwaiter
, TStateMachine
> (ref TAwaiter awaiter
, ref TStateMachine stateMachine
) where TAwaiter
: INotifyCompletion where TStateMachine
: IAsyncStateMachine
87 public void AwaitUnsafeOnCompleted
<TAwaiter
, TStateMachine
> (ref TAwaiter awaiter
, ref TStateMachine stateMachine
) where TAwaiter
: ICriticalNotifyCompletion where TStateMachine
: IAsyncStateMachine
92 public void Start
<TStateMachine
> (ref TStateMachine stateMachine
) where TStateMachine
: IAsyncStateMachine
97 public void SetStateMachine (IAsyncStateMachine stateMachine
)
105 public async MyTask
Test ()
107 await Task
.Delay (1);
110 public async MyTask
<int> Test2 ()
112 await Task
.Delay (1);
116 public async ValueTask
<string> Test3 ()
118 await Task
.Delay (1);
122 public static void Main ()
125 var r1
= x
.Test3 ().Result
;