TaskTree: Keep just one done handler

Instead of having separate handlers for done and errorOccurred.
This will enable setting just one common done handler with an
additional "bool success" argument.

Task-number: QTCREATORBUG-29834
Change-Id: I52d826dd89461ff93772a6fe7a85e432d1e84665
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Jarek Kobus
2023-10-31 16:30:12 +01:00
parent aef960a68c
commit 09c4aad0eb
2 changed files with 16 additions and 17 deletions

View File

@@ -138,8 +138,8 @@ public:
using TaskCreateHandler = std::function<TaskInterface *(void)>;
// Called prior to task start, just after createHandler
using TaskSetupHandler = std::function<SetupResult(TaskInterface &)>;
// Called on task done / error
using TaskEndHandler = std::function<void(const TaskInterface &)>;
// Called on task done, just before delete later
using TaskDoneHandler = std::function<void(const TaskInterface &, bool)>;
// Called when group entered
using GroupSetupHandler = std::function<SetupResult()>;
// Called when group done / error
@@ -148,8 +148,7 @@ public:
struct TaskHandler {
TaskCreateHandler m_createHandler;
TaskSetupHandler m_setupHandler = {};
TaskEndHandler m_doneHandler = {};
TaskEndHandler m_errorHandler = {};
TaskDoneHandler m_doneHandler = {};
};
struct GroupHandler {
@@ -331,7 +330,7 @@ public:
template <typename SetupHandler>
CustomTask(SetupHandler &&setup, const EndHandler &done = {}, const EndHandler &error = {})
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)),
wrapEnd(done), wrapEnd(error)}) {}
wrapEnds(done, error)}) {}
GroupItem withTimeout(std::chrono::milliseconds timeout,
const GroupEndHandler &handler = {}) const {
@@ -357,12 +356,14 @@ private:
};
};
static TaskEndHandler wrapEnd(const EndHandler &handler) {
if (!handler)
static TaskDoneHandler wrapEnds(const EndHandler &doneHandler, const EndHandler &errorHandler) {
if (!doneHandler && !errorHandler)
return {};
return [handler](const TaskInterface &taskInterface) {
return [doneHandler, errorHandler](const TaskInterface &taskInterface, bool success) {
const Adapter &adapter = static_cast<const Adapter &>(taskInterface);
handler(*adapter.task());
const auto handler = success ? doneHandler : errorHandler;
if (handler)
handler(*adapter.task());
};
};
};