From dd578354c448dbb92b12438886d80ac6c0c0bea7 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 15 Dec 2022 13:45:50 -0300 Subject: [PATCH] feat(Tasks): add ConcurrentTask::clear to allow re-using tasks This way old runs won't pile up in the internal DSs Signed-off-by: flow --- launcher/tasks/ConcurrentTask.cpp | 16 ++++++++++++++++ launcher/tasks/ConcurrentTask.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index ce08a6a2..bc3cf4d3 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -73,6 +73,22 @@ bool ConcurrentTask::abort() return suceedeed; } +void ConcurrentTask::clear() +{ + Q_ASSERT(!isRunning()); + + m_done.clear(); + m_failed.clear(); + m_queue.clear(); + + m_aborted = false; + + m_progress = 0; + m_stepProgress = 0; + + m_total_size = 0; +} + void ConcurrentTask::startNext() { if (m_aborted || m_doing.count() > m_total_max_size) diff --git a/launcher/tasks/ConcurrentTask.h b/launcher/tasks/ConcurrentTask.h index f1279d32..30b2ae4d 100644 --- a/launcher/tasks/ConcurrentTask.h +++ b/launcher/tasks/ConcurrentTask.h @@ -24,6 +24,11 @@ public: public slots: bool abort() override; + /** Resets the internal state of the task. + * This allows the same task to be re-used. + */ + void clear(); + protected slots: void executeTask() override;