TaskTree: Add Task c'tor taking one handler for done and error

The overloaded c'tor takes one done handler with an additional
"bool success" argument.

Task-number: QTCREATORBUG-29834
Change-Id: Id579d055721a2a07a5a9f0900aa4a73655f21610
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 17:03:48 +01:00
parent 09c4aad0eb
commit d35d0b5100
4 changed files with 51 additions and 45 deletions

View File

@@ -324,6 +324,7 @@ public:
static_assert(std::is_base_of_v<TaskAdapter<Task, Deleter>, Adapter>,
"The Adapter type for the CustomTask<Adapter> needs to be derived from "
"TaskAdapter<Task>.");
using DoneHandler = std::function<void(const Task &, bool)>;
using EndHandler = std::function<void(const Task &)>;
static Adapter *createAdapter() { return new Adapter; }
CustomTask() : GroupItem({&createAdapter}) {}
@@ -332,6 +333,11 @@ public:
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)),
wrapEnds(done, error)}) {}
template <typename SetupHandler>
CustomTask(SetupHandler &&setup, const DoneHandler &done)
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)), wrapDone(done)})
{}
GroupItem withTimeout(std::chrono::milliseconds timeout,
const GroupEndHandler &handler = {}) const {
return GroupItem::withTimeout(*this, timeout, handler);
@@ -366,6 +372,15 @@ private:
handler(*adapter.task());
};
};
static TaskDoneHandler wrapDone(const DoneHandler &handler) {
if (!handler)
return {};
return [handler](const TaskInterface &taskInterface, bool success) {
const Adapter &adapter = static_cast<const Adapter &>(taskInterface);
handler(*adapter.task(), success);
};
};
};
class TaskTreePrivate;