AsyncETVoidMethodBuilder.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.CompilerServices;
  4. using System.Security;
  5. namespace ET
  6. {
  7. internal struct AsyncETVoidMethodBuilder
  8. {
  9. // 1. Static Create method.
  10. [DebuggerHidden]
  11. public static AsyncETVoidMethodBuilder Create()
  12. {
  13. AsyncETVoidMethodBuilder builder = new AsyncETVoidMethodBuilder();
  14. return builder;
  15. }
  16. // 2. TaskLike Task property(void)
  17. [DebuggerHidden]
  18. public ETVoid Task => default;
  19. // 3. SetException
  20. [DebuggerHidden]
  21. public void SetException(Exception e)
  22. {
  23. ETTask.ExceptionHandler.Invoke(e);
  24. }
  25. // 4. SetResult
  26. [DebuggerHidden]
  27. public void SetResult()
  28. {
  29. // do nothing
  30. }
  31. // 5. AwaitOnCompleted
  32. [DebuggerHidden]
  33. public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
  34. {
  35. awaiter.OnCompleted(stateMachine.MoveNext);
  36. }
  37. // 6. AwaitUnsafeOnCompleted
  38. [DebuggerHidden]
  39. [SecuritySafeCritical]
  40. public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
  41. {
  42. awaiter.UnsafeOnCompleted(stateMachine.MoveNext);
  43. }
  44. // 7. Start
  45. [DebuggerHidden]
  46. public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
  47. {
  48. stateMachine.MoveNext();
  49. }
  50. // 8. SetStateMachine
  51. [DebuggerHidden]
  52. public void SetStateMachine(IAsyncStateMachine stateMachine)
  53. {
  54. }
  55. }
  56. }