Beispiel #1
0
        /// <summary> Resumers managed routines that are waiting for next frame. </summary>
        public void Update()
        {
            foreach (var resumer in nextFrameResumers)
            {
                resumer.Resume();
            }
            nextFrameResumers.Clear();

            //Cleanup dead routines
            var _maxRoot = maxRoot;

            maxRoot = -1;
            for (var i = 0; i <= _maxRoot; ++i)
            {
                var root = roots[i];
                if (root == null)
                {
                    continue;
                }
                if (root.IsDead)
                {
                    roots[i] = null;
                    CTask.Release(root);
                }
                else
                {
                    maxRoot = i;
                }
            }
        }
Beispiel #2
0
        /// <summary> Manages and runs a routine. </summary>
        public CTaskHandle Run(CTask task, Action <Exception> onStop = null)
        {
            task.SetManager(this, onStop ?? DefaultOnStop);

            var added = false;

            for (var i = 0; i < roots.Count; ++i)
            {
                if (roots[i] == null)
                {
                    maxRoot  = Mathf.Max(maxRoot, i);
                    roots[i] = task;
                    added    = true;
                    break;
                }
            }
            if (!added)
            {
                maxRoot = roots.Count;
                roots.Add(task);
            }

            task.Step();
            return(new CTaskHandle(task));
        }
Beispiel #3
0
 /// <summary> Stops all managed routines. </summary>
 public void StopAll()
 {
     for (var i = 0; i < roots.Count; ++i)
     {
         if (roots[i] == null)
         {
             continue;
         }
         CTask.Release(roots[i]);
         roots[i] = null;
     }
 }
Beispiel #4
0
        public static CTask <T> GetAwaiter <T>(this IResumer <T> resumer)
        {
            var _resumer = resumer as Resumer <T>;

            Assert.IsNotNull(_resumer);
            var resumerRoutine = CTask.Get <CTask <T> >(true);

            resumerRoutine.Trace(1);
            _resumer.routine = resumerRoutine;
            _resumer.id      = resumerRoutine.Id;
            if (_resumer.WasResumed)
            {
                resumerRoutine.SetResult(_resumer.result);
                _resumer.Reset();
            }
            return(resumerRoutine);
        }
 /// <summary> Manages and runs a routine. </summary>
 public CTaskHandle Run(CTask routine, Action <Exception> onStop = null)
 {
     return(routineManager.Run(routine, onStop));
 }
Beispiel #6
0
 public CTaskHandle(CTask routine)
 {
     this.routine = routine;
     id           = routine.Id;
 }
Beispiel #7
0
 public static CTask GetAwaiter(this CustomYieldInstruction customYieldInstruction)
 {
     return(CTask.WaitForCustomYieldInstruction(customYieldInstruction).GetAwaiter());
 }
Beispiel #8
0
 public static CTask GetAwaiter(this AsyncOperation asyncOperation)
 {
     return(CTask.WaitForAsyncOperation(asyncOperation).GetAwaiter());
 }