fix: abort logic running subsequent tasks anyways some times

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-07-24 17:16:14 -03:00
parent c410bb4ecb
commit bdf464e792
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 16 additions and 8 deletions

View File

@ -45,25 +45,31 @@ void ConcurrentTask::executeTask()
bool ConcurrentTask::abort() bool ConcurrentTask::abort()
{ {
m_queue.clear();
m_aborted = true;
if (m_doing.isEmpty()) { if (m_doing.isEmpty()) {
// Don't call emitAborted() here, we want to bypass the 'is the task running' check // Don't call emitAborted() here, we want to bypass the 'is the task running' check
emit aborted(); emit aborted();
emit finished(); emit finished();
m_aborted = true;
return true; return true;
} }
m_queue.clear(); bool suceedeed = true;
m_aborted = true; QMutableHashIterator<Task*, Task::Ptr> doing_iter(m_doing);
for (auto task : m_doing) while (doing_iter.hasNext()) {
m_aborted &= task->abort(); auto task = doing_iter.next();
suceedeed &= (task.value())->abort();
}
if (m_aborted) if (suceedeed)
emitAborted(); emitAborted();
else
emitFailed(tr("Failed to abort all running tasks."));
return m_aborted; return suceedeed;
} }
void ConcurrentTask::startNext() void ConcurrentTask::startNext()

View File

@ -9,7 +9,9 @@ class ConcurrentTask : public Task {
Q_OBJECT Q_OBJECT
public: public:
explicit ConcurrentTask(QObject* parent = nullptr, QString task_name = "", int max_concurrent = 6); explicit ConcurrentTask(QObject* parent = nullptr, QString task_name = "", int max_concurrent = 6);
virtual ~ConcurrentTask(); ~ConcurrentTask() override;
bool canAbort() const override { return true; }
inline auto isMultiStep() const -> bool override { return m_queue.size() > 1; }; inline auto isMultiStep() const -> bool override { return m_queue.size() > 1; };
auto getStepProgress() const -> qint64 override; auto getStepProgress() const -> qint64 override;