feat(Tasks): allow adding subtasks while running in ConcurrentTask

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-12-15 13:46:51 -03:00
parent dd578354c4
commit b0c866bfaa
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469

View File

@ -27,10 +27,8 @@ auto ConcurrentTask::getStepTotalProgress() const -> qint64
void ConcurrentTask::addTask(Task::Ptr task)
{
if (!isRunning())
m_queue.append(task);
else
qWarning() << "Tried to add a task to a running concurrent task!";
m_queue.append(task);
m_total_size += 1;
}
void ConcurrentTask::executeTask()
@ -117,9 +115,14 @@ void ConcurrentTask::startNext()
setStepStatus(next->isMultiStep() ? next->getStepStatus() : next->getStatus());
updateState();
QCoreApplication::processEvents();
QMetaObject::invokeMethod(next.get(), &Task::start, Qt::QueuedConnection);
next->start();
// Allow going up the number of concurrent tasks in case of tasks being added in the middle of a running task.
int num_starts = m_total_max_size - m_doing.size();
for (int i = 0; i < num_starts; i++)
QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
QCoreApplication::processEvents();
}
void ConcurrentTask::subTaskSucceeded(Task::Ptr task)