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 <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-12-15 13:45:50 -03:00
parent 4f1ea712da
commit dd578354c4
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 21 additions and 0 deletions

View File

@ -73,6 +73,22 @@ bool ConcurrentTask::abort()
return suceedeed; 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() void ConcurrentTask::startNext()
{ {
if (m_aborted || m_doing.count() > m_total_max_size) if (m_aborted || m_doing.count() > m_total_max_size)

View File

@ -24,6 +24,11 @@ public:
public slots: public slots:
bool abort() override; bool abort() override;
/** Resets the internal state of the task.
* This allows the same task to be re-used.
*/
void clear();
protected protected
slots: slots:
void executeTask() override; void executeTask() override;