You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

75 rivejä
1.5 KiB

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