Ejemplo n.º 1
0
 public void RequeueCurrentAction()
 {
     if (currentAction != null)
     {
         Requeue(currentAction);
         currentAction = null;
     }
 }
Ejemplo n.º 2
0
        public SyncAction Dequeue()
        {
            SyncAction action = null;

            if (queue.Count > 0)
            {
                action = queue[0];
                queue.RemoveAt(0);
            }

            currentAction = action;
            return(action);
        }
Ejemplo n.º 3
0
 public void Requeue(SyncAction action)
 {
     queue.Insert(0, action);
 }
Ejemplo n.º 4
0
 public void Enqueue(SyncAction action)
 {
     queue.Add(action);
 }
Ejemplo n.º 5
0
        private IEnumerator ProcessQueue()
        {
            if (finished)
            {
                // Already finished, exit the coroutine.
                yield break;
            }

            processing = true;
            bool failed = false;

            SyncAction action = Dequeue();

            while (action != null)
            {
                Debug.Log("Processing Action: " + action.GetType().Name);

                yield return(null);

                // Reset all fields in case this is a retry.
                action.isDone     = false;
                action.succeeded  = false;
                action.retry      = false;
                action.retryDelay = 0.0f;

                action.Process(this);

                while (!action.isDone)
                {
                    yield return(null);
                }

                Debug.Log("Action " + action.GetType().Name + " " + (action.succeeded ? "Succeeded" : (action.retry ? "Retry" : "Failed")));

                if (!action.succeeded)
                {
                    RequeueCurrentAction();

                    if (!action.retry)
                    {
                        // Fatal error, stop the queue.
                        failed = true;
                        DestroyImmediate(action);
                        break;
                    }
                    else if (action.retryDelay > 0)
                    {
                        // Wait delay seconds and try again.
                        Insert(TimerSyncAction.CreateInstance(action.retryDelay), 0);
                    }
                }
                else
                {
                    DestroyImmediate(action);
                }

                yield return(null);

                action = Dequeue();
            }

            if (onCompleteAction != null)
            {
                onCompleteAction.succeeded = !failed;
                onCompleteAction.Process(this);
                DestroyImmediate(onCompleteAction);
            }

            processing = false;
            finished   = true;

            if (OnQueueFinished != null)
            {
                OnQueueFinished();
            }
        }
Ejemplo n.º 6
0
 public void Insert(SyncAction action, int index)
 {
     queue.Insert(index, action);
 }