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,
|
GroupItem GroupItem::withTimeout(const GroupItem &item, milliseconds timeout,
|
||||||
const GroupEndHandler &handler)
|
const GroupEndHandler &handler)
|
||||||
{
|
{
|
||||||
const TimeoutTask::EndHandler taskHandler = handler
|
const TimeoutTask::EndFunction taskHandler = handler
|
||||||
? [handler](const milliseconds &) { handler(); } : TimeoutTask::EndHandler();
|
? [handler](const milliseconds &) { handler(); } : TimeoutTask::EndFunction();
|
||||||
return Group {
|
return Group {
|
||||||
parallel,
|
parallel,
|
||||||
stopOnFinished,
|
stopOnFinished,
|
||||||
|
@@ -324,17 +324,18 @@ public:
|
|||||||
static_assert(std::is_base_of_v<TaskAdapter<Task, Deleter>, Adapter>,
|
static_assert(std::is_base_of_v<TaskAdapter<Task, Deleter>, Adapter>,
|
||||||
"The Adapter type for the CustomTask<Adapter> needs to be derived from "
|
"The Adapter type for the CustomTask<Adapter> needs to be derived from "
|
||||||
"TaskAdapter<Task>.");
|
"TaskAdapter<Task>.");
|
||||||
using DoneHandler = std::function<void(const Task &, bool)>;
|
using SetupFunction = std::function<void(const Task &)>;
|
||||||
using EndHandler = 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; }
|
static Adapter *createAdapter() { return new Adapter; }
|
||||||
CustomTask() : GroupItem({&createAdapter}) {}
|
CustomTask() : GroupItem({&createAdapter}) {}
|
||||||
template <typename SetupHandler>
|
template <typename SetupHandler = SetupFunction>
|
||||||
CustomTask(SetupHandler &&setup, const EndHandler &done = {}, const EndHandler &error = {})
|
CustomTask(SetupHandler &&setup, const EndFunction &done = {}, const EndFunction &error = {})
|
||||||
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)),
|
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)),
|
||||||
wrapEnds(done, error)}) {}
|
wrapEnds(done, error)}) {}
|
||||||
|
|
||||||
template <typename SetupHandler>
|
template <typename SetupHandler>
|
||||||
CustomTask(SetupHandler &&setup, const DoneHandler &done)
|
CustomTask(SetupHandler &&setup, const DoneFunction &done)
|
||||||
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)), wrapDone(done)})
|
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)), wrapDone(done)})
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -346,6 +347,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
template<typename SetupHandler>
|
template<typename SetupHandler>
|
||||||
static GroupItem::TaskSetupHandler wrapSetup(SetupHandler &&handler) {
|
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,
|
static constexpr bool isDynamic = std::is_same_v<SetupResult,
|
||||||
std::invoke_result_t<std::decay_t<SetupHandler>, typename Adapter::TaskType &>>;
|
std::invoke_result_t<std::decay_t<SetupHandler>, typename Adapter::TaskType &>>;
|
||||||
constexpr bool isVoid = std::is_same_v<void,
|
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)
|
if (!doneHandler && !errorHandler)
|
||||||
return {};
|
return {};
|
||||||
return [doneHandler, errorHandler](const TaskInterface &taskInterface, bool success) {
|
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)
|
if (!handler)
|
||||||
return {};
|
return {};
|
||||||
return [handler](const TaskInterface &taskInterface, bool success) {
|
return [handler](const TaskInterface &taskInterface, bool success) {
|
||||||
|
@@ -117,12 +117,16 @@ void tst_Tasking::validConstructs()
|
|||||||
|
|
||||||
const Group task2 {
|
const Group task2 {
|
||||||
parallel,
|
parallel,
|
||||||
|
TestTask(),
|
||||||
TestTask(setupHandler),
|
TestTask(setupHandler),
|
||||||
TestTask(setupHandler, finishHandler),
|
TestTask(setupHandler, finishHandler),
|
||||||
TestTask(setupHandler, finishHandler, errorHandler),
|
TestTask(setupHandler, finishHandler, errorHandler),
|
||||||
TestTask(setupHandler, doneHandler),
|
TestTask(setupHandler, doneHandler),
|
||||||
// need to explicitly pass empty handler for done
|
// 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.
|
// When turning each of below blocks on, you should see the specific compiler error message.
|
||||||
|
Reference in New Issue
Block a user