feat(Tasks): allow adding subtasks while running in ConcurrentTask
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
dd578354c4
commit
b0c866bfaa
@ -27,10 +27,8 @@ auto ConcurrentTask::getStepTotalProgress() const -> qint64
|
|||||||
|
|
||||||
void ConcurrentTask::addTask(Task::Ptr task)
|
void ConcurrentTask::addTask(Task::Ptr task)
|
||||||
{
|
{
|
||||||
if (!isRunning())
|
|
||||||
m_queue.append(task);
|
m_queue.append(task);
|
||||||
else
|
m_total_size += 1;
|
||||||
qWarning() << "Tried to add a task to a running concurrent task!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConcurrentTask::executeTask()
|
void ConcurrentTask::executeTask()
|
||||||
@ -117,9 +115,14 @@ void ConcurrentTask::startNext()
|
|||||||
setStepStatus(next->isMultiStep() ? next->getStepStatus() : next->getStatus());
|
setStepStatus(next->isMultiStep() ? next->getStepStatus() : next->getStatus());
|
||||||
updateState();
|
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)
|
void ConcurrentTask::subTaskSucceeded(Task::Ptr task)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user