95 template <
typename tRet>
100 WeakTask weakTask = std::move(in_task);
104 template <
typename tRet>
107 static_assert(static_false<tRet>::value,
"Cannot run an unmanaged task by copy (try Run(std::move(task)))");
114 template <
typename tRet>
119 m_strongRefs.push_back(
Run(std::move(in_task)));
120 return weakTaskHandle;
122 template <
typename tRet>
125 static_assert(static_false<tRet>::value,
"Cannot run a managed task by copy (try RunManaged(std::move(task)))");
136 m_tasks.push_back(std::move(in_task));
145 m_strongRefs.clear();
153 std::vector<WeakTaskHandle> weakHandles;
154 for(
auto& task : m_tasks)
157 weakHandles.push_back(task);
161 return [](std::vector<WeakTaskHandle> in_weakHandles) ->
Task<> {
163 for(
const auto& weakHandle : in_weakHandles)
167 }(std::move(weakHandles));
175 for(
size_t readIdx = 0; readIdx < m_tasks.size(); ++readIdx)
179 if(writeIdx != readIdx)
181 m_tasks[writeIdx] = std::move(m_tasks[readIdx]);
186 m_tasks.resize(writeIdx);
189 auto removeIt = m_strongRefs.erase(std::remove_if(m_strongRefs.begin(), m_strongRefs.end(), [](
const auto& in_taskHandle) {
190 return in_taskHandle.IsDone();
191 }), m_strongRefs.end());
195 std::string
GetDebugString(std::optional<TaskDebugStackFormatter> in_formatter = {})
const
197 std::string debugStr;
198 for(
const auto& task : m_tasks)
206 debugStr += task.GetDebugStack(in_formatter);
213 std::vector<WeakTask> m_tasks;
214 std::vector<TaskHandle<>> m_strongRefs;
void RequestStop()
Issues a request for the task to terminate gracefully as soon as possible.
Definition: Task.h:289
Manager that runs and resumes a collection of tasks.
Definition: TaskManager.h:88
WeakTaskHandle RunManaged(Task< tRet > &&in_task)
Run a managed task.
Definition: TaskManager.h:115
void KillAllTasks()
Call Task::Kill() on all tasks (managed + unmanaged)
Definition: TaskManager.h:140
TaskHandle< tRet > Run(Task< tRet > &&in_task)
Destructor (disables copy/move construction + assignment)
Definition: TaskManager.h:96
void RunWeakTask(WeakTask &&in_task)
Run a weak task.
Definition: TaskManager.h:133
Task StopAllTasks()
Issue a stop request using Task::RequestStop() on all active tasks (managed and unmanaged)
Definition: TaskManager.h:150
void Update()
Call Task::Resume() on all active tasks exactly once (managed + unmanaged)
Definition: TaskManager.h:171
std::string GetDebugString(std::optional< TaskDebugStackFormatter > in_formatter={}) const
Get a debug string containing a list of all active tasks.
Definition: TaskManager.h:195
#define TASK_NAME(...)
Macro that instruments a task with a debug name string. Usually at the top of every task coroutine as...
Definition: Task.h:25
@ Done
Task has terminated and coroutine frame has been destroyed.