BadScript 2
Loading...
Searching...
No Matches
BadTaskRunner.cs
Go to the documentation of this file.
2
4
8public class BadTaskRunner
9{
13 public static readonly BadTaskRunner Instance = new BadTaskRunner();
14
18 private readonly List<BadTask> m_TaskList = new List<BadTask>();
19
27
28
32 public BadTask? Current { get; private set; }
33
37 public bool IsIdle => m_TaskList.Count == 0;
38
42 public void RunStep()
43 {
44 for (int i = m_TaskList.Count - 1; i >= 0; --i)
45 {
46 if (i >= m_TaskList.Count)
47 {
48 continue;
49 }
50
51 BadTask t = m_TaskList[i];
52 Current = t;
53
54 if (t.IsPaused)
55 {
56 continue;
57 }
58
59 if (!t.IsFinished)
60 {
61 for (int j = 0; j < BadTaskRunnerSettings.Instance.TaskIterationTime; j++)
62 {
63 if (t.IsPaused)
64 {
65 break;
66 }
67
68 if (!t.IsFinished && t.Runnable.Enumerator.MoveNext())
69 {
70 continue;
71 }
72
73 t.Stop();
74
75 break;
76 }
77 }
78
79 if (!t.IsFinished)
80 {
81 continue;
82 }
83
84 m_TaskList.Remove(t);
85
86 foreach (BadTask x in t.ContinuationTasks)
87 {
88 if (x.IsFinished)
89 {
90 continue;
91 }
92
93 if (m_TaskList.Contains(x))
94 {
95 x.Resume();
96 }
97 else
98 {
99 m_TaskList.Add(x);
100 x.Start();
101 }
102 }
103 }
104 }
105
109 public void Clear()
110 {
111 m_TaskList.Clear();
112 }
113
118 public void ClearTasksFrom(BadTask creator)
119 {
120 foreach (BadTask task in m_TaskList.Where(task => task.Creator == creator))
121 {
122 task.Cancel();
123 ClearTasksFrom(task);
124 }
125 }
126
132 public bool IsTaskAdded(BadTask task)
133 {
134 return m_TaskList.Contains(task);
135 }
136
142 public void AddTask(BadTask task, bool runImmediately = false)
143 {
144 m_TaskList.Add(task);
145 task.SetCreator(Current);
146
147 if (runImmediately)
148 {
149 task.Start();
150 }
151 }
152}
Implements the parse for the 'await' Expression.
IEnumerator< BadObject > Enumerator
The Enumerator of the Runnable.
Implements a Task Object.
Definition BadTask.cs:17
void Resume()
Resumes the Task.
Definition BadTask.cs:228
void SetCreator(BadTask? task)
Sets the Creator of this Task.
Definition BadTask.cs:185
bool IsPaused
Is true if the task is running.
Definition BadTask.cs:137
void Start()
Starts the Task.
Definition BadTask.cs:193
BadTask? Creator
The Creator of this Task.
Definition BadTask.cs:112
bool IsFinished
Is true if the task is finished.
Definition BadTask.cs:132
IEnumerable< BadTask > ContinuationTasks
Enumeration of Continuation Tasks.
Definition BadTask.cs:107
void Cancel()
Cancels the Task.
Definition BadTask.cs:212
BadRunnable Runnable
Runnable of the Task.
Definition BadTask.cs:102
void RunStep()
Runs a single step of the Task Runner.
static BadTaskRunner()
Static Constructor.
void ClearTasksFrom(BadTask creator)
Clears all Tasks from the given Creator.
void AddTask(BadTask task, bool runImmediately=false)
Adds a Task to the Task Runner.
static readonly BadTaskRunner Instance
The Task Runner Instance.
bool IsTaskAdded(BadTask task)
Checks if a Task is added to the Task Runner.
readonly List< BadTask > m_TaskList
The Task List.
bool IsIdle
Is true if there are no tasks to run.
Implements the Operator Table used by the Parser.
void AddValueParser(BadValueParser parser)
Adds a Value parser to the List of Value Parsers.
static BadOperatorTable Instance
The Operator Table Instance.
static T Instance
Returns the Instance of the Settings Provider.
Contains task/async Extensions and Integrations for the BadScript2 Runtime.
Contains the Operators for the BadScript2 Language.