AsyncETTaskCompletedMethodBuilder.cs 1.9 KB

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