Beispiel #1
0
 private bool RemoveFinishedTask(LiteTask task)
 {
     if (!task.IsDone)
     {
         return(false);
     }
     task.RestartTask(null, true);
     pool.Push(task);
     return(true);
 }
Beispiel #2
0
 public LiteTask Get(out LiteTask task, IEnumerator routine = null, bool startInBackground = true)
 {
     lock (pool)
     {
         if (pool.Count == 0)
         {
             return(task = new LiteTask(routine, startInBackground));
         }
         else
         {
             task = pool.Pop();
             set.Remove(task);
             return(task.RestartTask(routine, startInBackground));
         }
     }
 }
Beispiel #3
0
        public void Release(LiteTask task)
        {
            lock (pool)
            {
                if (task != null && set.Add(task))
                {
                    task.Cancel();

                    if (task.IsDone)
                    {
                        task.RestartTask(null, true);
                        pool.Push(task);
                    }
                    else
                    {
                        if (runningTasks == null)
                        {
                            runningTasks = new List <LiteTask>()
                            {
                                task
                            };
                            removeFinishedTask = RemoveFinishedTask;
                        }
                        else
                        {
                            runningTasks.Add(task);
                        }

                        if (waitRoutine.IsNullOrDone())
                        {
                            LiteCoroutine.StartCoroutine(ref waitRoutine, WaitForTasks());
                        }
                    }
                }
            }
        }