Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

96 Zeilen
2.0 KiB

  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace SUISS.Cloud
  5. {
  6. public class CloudRequest<TResult, TError> : CustomYieldInstruction
  7. {
  8. public CloudRequest(IEnumerator coroutine)
  9. {
  10. this._routine = this.InternalRoutine(coroutine);
  11. this._error = default(TError);
  12. this._result = default(TResult);
  13. this._yieldable = CloudRequestRunner.StartCoroutine(this._routine);
  14. }
  15. public TResult Result
  16. {
  17. get
  18. {
  19. if (!this.IsDone)
  20. {
  21. throw new Exception(string.Format("{0}.Result was read before return value was set!", this));
  22. }
  23. return this._result;
  24. }
  25. }
  26. public TError Error
  27. {
  28. get
  29. {
  30. if (!this.IsDone)
  31. {
  32. throw new Exception(string.Format("{0}.Error was read before return error was set!", this));
  33. }
  34. return this._error;
  35. }
  36. }
  37. public bool IsDone
  38. {
  39. get
  40. {
  41. return !this.keepWaiting;
  42. }
  43. }
  44. public override bool keepWaiting
  45. {
  46. get
  47. {
  48. return this._yieldable.keepWaiting;
  49. }
  50. }
  51. private IEnumerator InternalRoutine(IEnumerator coroutine)
  52. {
  53. while (coroutine.MoveNext())
  54. {
  55. object obj = coroutine.Current;
  56. YieldReturn returned = obj as YieldReturn;
  57. if (returned != null)
  58. {
  59. YieldError<TError> yieldError = coroutine.Current as YieldError<TError>;
  60. YieldResult<TResult> yieldResult = coroutine.Current as YieldResult<TResult>;
  61. if (yieldError != null)
  62. {
  63. this._error = yieldError.Value;
  64. yield break;
  65. }
  66. if (yieldResult != null)
  67. {
  68. this._result = yieldResult.Value;
  69. yield break;
  70. }
  71. throw new Exception(string.Format("Type missmatch! {0} returned a wrong value {1} to {2}!", coroutine, returned, this));
  72. }
  73. else
  74. {
  75. yield return coroutine.Current;
  76. }
  77. }
  78. yield break;
  79. }
  80. private TError _error;
  81. private TResult _result;
  82. private IEnumerator _routine;
  83. private CustomYieldInstruction _yieldable;
  84. }
  85. }