123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Diagnostics;
- using System.Runtime.CompilerServices;
- using System.Security;
- namespace ET
- {
- public struct ETAsyncTaskMethodBuilder
- {
- private ETTask tcs;
- // 1. Static Create method.
- [DebuggerHidden]
- public static ETAsyncTaskMethodBuilder Create()
- {
- ETAsyncTaskMethodBuilder builder = new ETAsyncTaskMethodBuilder() { tcs = ETTask.Create(true) };
- return builder;
- }
- // 2. TaskLike Task property.
- [DebuggerHidden]
- public ETTask Task => this.tcs;
- // 3. SetException
- [DebuggerHidden]
- public void SetException(Exception exception)
- {
- this.tcs.SetException(exception);
- }
- // 4. SetResult
- [DebuggerHidden]
- public void SetResult()
- {
- this.tcs.SetResult();
- }
- // 5. AwaitOnCompleted
- [DebuggerHidden]
- public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
- {
- awaiter.OnCompleted(stateMachine.MoveNext);
- }
- // 6. AwaitUnsafeOnCompleted
- [DebuggerHidden]
- [SecuritySafeCritical]
- public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
- {
- awaiter.OnCompleted(stateMachine.MoveNext);
- }
- // 7. Start
- [DebuggerHidden]
- public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
- {
- stateMachine.MoveNext();
- }
- // 8. SetStateMachine
- [DebuggerHidden]
- public void SetStateMachine(IAsyncStateMachine stateMachine)
- {
- }
- }
- public struct ETAsyncTaskMethodBuilder<T>
- {
- private ETTask<T> tcs;
- // 1. Static Create method.
- [DebuggerHidden]
- public static ETAsyncTaskMethodBuilder<T> Create()
- {
- ETAsyncTaskMethodBuilder<T> builder = new ETAsyncTaskMethodBuilder<T>() { tcs = ETTask<T>.Create(true) };
- return builder;
- }
- // 2. TaskLike Task property.
- [DebuggerHidden]
- public ETTask<T> Task => this.tcs;
- // 3. SetException
- [DebuggerHidden]
- public void SetException(Exception exception)
- {
- this.tcs.SetException(exception);
- }
- // 4. SetResult
- [DebuggerHidden]
- public void SetResult(T ret)
- {
- this.tcs.SetResult(ret);
- }
- // 5. AwaitOnCompleted
- [DebuggerHidden]
- public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
- {
- awaiter.OnCompleted(stateMachine.MoveNext);
- }
- // 6. AwaitUnsafeOnCompleted
- [DebuggerHidden]
- [SecuritySafeCritical]
- public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
- {
- awaiter.OnCompleted(stateMachine.MoveNext);
- }
- // 7. Start
- [DebuggerHidden]
- public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
- {
- stateMachine.MoveNext();
- }
- // 8. SetStateMachine
- [DebuggerHidden]
- public void SetStateMachine(IAsyncStateMachine stateMachine)
- {
- }
- }
- }
|