|
- using System;
- using System.Collections;
- using UnityEngine;
-
- namespace SUISS.Cloud
- {
- public class CloudRequest<TError> : CustomYieldInstruction
- {
- public CloudRequest(IEnumerator coroutine)
- {
- this._routine = this.InternalRoutine(coroutine);
- this._error = default(TError);
- this._yieldable = CloudRequestRunner.StartCoroutine(this._routine);
- }
-
- public TError Error
- {
- get
- {
- if (!this.IsDone)
- {
- throw new Exception(string.Format("{0}.Error was read before return error was set!", this));
- }
- return this._error;
- }
- }
-
- public bool IsDone
- {
- get
- {
- return !this.keepWaiting;
- }
- }
-
- public override bool keepWaiting
- {
- get
- {
- return this._yieldable.keepWaiting;
- }
- }
-
- private IEnumerator InternalRoutine(IEnumerator coroutine)
- {
- while (coroutine.MoveNext())
- {
- object obj = coroutine.Current;
- YieldReturn returned = obj as YieldReturn;
- if (returned != null)
- {
- YieldError<TError> yieldError = coroutine.Current as YieldError<TError>;
- if (yieldError != null)
- {
- this._error = yieldError.Value;
- yield break;
- }
- throw new Exception(string.Format("Type missmatch! {0} returned a wrong value {1} to {2}!", coroutine, returned, this));
- }
- else
- {
- yield return coroutine.Current;
- }
- }
- yield break;
- }
-
- private TError _error;
-
- private IEnumerator _routine;
-
- private CustomYieldInstruction _yieldable;
- }
- }
|