forked from qt-creator/qt-creator
TaskTree: Make setup handler optional
Change-Id: Idfcaaf5cc5f69895d8cf9bf6e4ee673e524b61fe Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -956,8 +956,8 @@ void GroupItem::addChildren(const QList<GroupItem> &children)
|
||||
GroupItem GroupItem::withTimeout(const GroupItem &item, milliseconds timeout,
|
||||
const GroupEndHandler &handler)
|
||||
{
|
||||
const TimeoutTask::EndHandler taskHandler = handler
|
||||
? [handler](const milliseconds &) { handler(); } : TimeoutTask::EndHandler();
|
||||
const TimeoutTask::EndFunction taskHandler = handler
|
||||
? [handler](const milliseconds &) { handler(); } : TimeoutTask::EndFunction();
|
||||
return Group {
|
||||
parallel,
|
||||
stopOnFinished,
|
||||
|
@@ -324,17 +324,18 @@ 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 &)>;
|
||||
using SetupFunction = std::function<void(const Task &)>;
|
||||
using DoneFunction = std::function<void(const Task &, bool)>;
|
||||
using EndFunction = std::function<void(const Task &)>;
|
||||
static Adapter *createAdapter() { return new Adapter; }
|
||||
CustomTask() : GroupItem({&createAdapter}) {}
|
||||
template <typename SetupHandler>
|
||||
CustomTask(SetupHandler &&setup, const EndHandler &done = {}, const EndHandler &error = {})
|
||||
template <typename SetupHandler = SetupFunction>
|
||||
CustomTask(SetupHandler &&setup, const EndFunction &done = {}, const EndFunction &error = {})
|
||||
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)),
|
||||
wrapEnds(done, error)}) {}
|
||||
|
||||
template <typename SetupHandler>
|
||||
CustomTask(SetupHandler &&setup, const DoneHandler &done)
|
||||
CustomTask(SetupHandler &&setup, const DoneFunction &done)
|
||||
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)), wrapDone(done)})
|
||||
{}
|
||||
|
||||
@@ -346,6 +347,8 @@ public:
|
||||
private:
|
||||
template<typename SetupHandler>
|
||||
static GroupItem::TaskSetupHandler wrapSetup(SetupHandler &&handler) {
|
||||
if constexpr (std::is_same_v<SetupHandler, std::function<void()>>)
|
||||
return {}; // When user passed {} for setup handler.
|
||||
static constexpr bool isDynamic = std::is_same_v<SetupResult,
|
||||
std::invoke_result_t<std::decay_t<SetupHandler>, typename Adapter::TaskType &>>;
|
||||
constexpr bool isVoid = std::is_same_v<void,
|
||||
@@ -362,7 +365,7 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
static TaskDoneHandler wrapEnds(const EndHandler &doneHandler, const EndHandler &errorHandler) {
|
||||
static TaskDoneHandler wrapEnds(const EndFunction &doneHandler, const EndFunction &errorHandler) {
|
||||
if (!doneHandler && !errorHandler)
|
||||
return {};
|
||||
return [doneHandler, errorHandler](const TaskInterface &taskInterface, bool success) {
|
||||
@@ -373,7 +376,7 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
static TaskDoneHandler wrapDone(const DoneHandler &handler) {
|
||||
static TaskDoneHandler wrapDone(const DoneFunction &handler) {
|
||||
if (!handler)
|
||||
return {};
|
||||
return [handler](const TaskInterface &taskInterface, bool success) {
|
||||
|
@@ -117,12 +117,16 @@ void tst_Tasking::validConstructs()
|
||||
|
||||
const Group task2 {
|
||||
parallel,
|
||||
TestTask(),
|
||||
TestTask(setupHandler),
|
||||
TestTask(setupHandler, finishHandler),
|
||||
TestTask(setupHandler, finishHandler, errorHandler),
|
||||
TestTask(setupHandler, doneHandler),
|
||||
// need to explicitly pass empty handler for done
|
||||
TestTask(setupHandler, {}, errorHandler)
|
||||
TestTask(setupHandler, {}, errorHandler),
|
||||
TestTask({}, finishHandler),
|
||||
TestTask({}, finishHandler, errorHandler),
|
||||
TestTask({}, {}, errorHandler)
|
||||
};
|
||||
|
||||
// When turning each of below blocks on, you should see the specific compiler error message.
|
||||
|
Reference in New Issue
Block a user