diff --git a/include/Private/TaskPrivate.h b/include/Private/TaskPrivate.h index 2f4099d..8d0ea39 100644 --- a/include/Private/TaskPrivate.h +++ b/include/Private/TaskPrivate.h @@ -68,6 +68,8 @@ struct TaskDebugStackFormatter return std::string((long long)in_indent * 2, ' '); } }; + +#if SQUID_ENABLE_TASK_DEBUG static std::string FormatDebugString(std::string in_str) { std::replace(in_str.begin(), in_str.end(), '\n', ' '); @@ -75,7 +77,6 @@ static std::string FormatDebugString(std::string in_str) } //--- SetDebugName Awaiter ---// -#if SQUID_ENABLE_TASK_DEBUG struct SetDebugName { // Sets a Task's debug name field diff --git a/include/Task.h b/include/Task.h index 2d860ed..868666b 100644 --- a/include/Task.h +++ b/include/Task.h @@ -265,12 +265,12 @@ public: return *this; } template - bool operator ==(const Task& in_otherTask) noexcept + bool operator ==(const Task& in_otherTask) const noexcept { return m_taskInternal == in_otherTask.m_taskInternal; } template - bool operator !=(const Task& in_otherTask) noexcept + bool operator !=(const Task& in_otherTask) const noexcept { return m_taskInternal != in_otherTask.m_taskInternal; } @@ -343,7 +343,7 @@ public: { return ""; // Returns an empty string when task debug is disabled } - [[nodiscard]] std::string GetDebugStack(std::optional in_formatter = {}) const /// @private + [[nodiscard]] std::string GetDebugStack([[maybe_unused]] std::optional in_formatter = {}) const /// @private { return ""; // Returns an empty string when task debug is disabled } @@ -496,6 +496,16 @@ public: return StopTaskIf(std::move(*this), in_cancelFn, in_timeout, in_timeFn); } + Task MergeWith(WeakTask&& in_weak) + { + static_assert(IsStrong() && !IsResumable(), "Can only merge a strong, non-resumable and a weak, resumable task."); + assert(in_weak == *this); // can only merge if both refer to the same task + + Task result_task = in_weak.MoveToTask(); + *this = nullptr; + return result_task; + } + private: /// @cond template friend struct TaskAwaiterBase; diff --git a/include/TaskManager.h b/include/TaskManager.h index 3365d5d..6c29f55 100644 --- a/include/TaskManager.h +++ b/include/TaskManager.h @@ -136,7 +136,7 @@ public: m_tasks.push_back(std::move(in_task)); } - bool IsManagedTask(const WeakTaskHandle& in_task) + bool IsManagedTask(const WeakTaskHandle& in_task) const { return std::find(m_strongRefs.begin(), m_strongRefs.end(), in_task) != m_strongRefs.end(); }