TaskTree: Add synchronous invocation (Tasking::Sync)

Make it possible to mix synchronous and asynchronous calls
inside task tree.

Basically, it's a shortcut for:

bool syncMethod();
Group {
    OnGroupSetup([syncMethod] { return syncMethod()
                                ? TaskAction::StopWithDone
                                : TaskAction::StopWithError; })
}

Please note: similarly to Group, Sync isn't counted as a task
inside taskCount() and doesn't emit TaskTree::progressValueChanged()
when finished. It's being considered as a simple handler
that doesn't last long and shouldn't block the GUI thread.
Otherwise, use AsyncTask instead.

Change-Id: If71c5da2f9b202a69c41a555cc93d314476952f4
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2023-02-06 20:27:59 +01:00
parent 2f5aed6c78
commit 06dda40ccc
2 changed files with 95 additions and 1 deletions

View File

@@ -244,6 +244,16 @@ public:
OnGroupError(const GroupEndHandler &handler) : TaskItem({{}, {}, handler}) {}
};
// Synchronous invocation. Similarly to Group - isn't counted as a task inside taskCount()
class QTCREATOR_UTILS_EXPORT Sync : public Group
{
public:
using SynchronousMethod = std::function<bool()>;
Sync(const SynchronousMethod &sync)
: Group({OnGroupSetup([sync] { return sync() ? TaskAction::StopWithDone
: TaskAction::StopWithError; })}) {}
};
QTCREATOR_UTILS_EXPORT extern ParallelLimit sequential;
QTCREATOR_UTILS_EXPORT extern ParallelLimit parallel;
QTCREATOR_UTILS_EXPORT extern Workflow stopOnError;