TaskTree: Get rid of OnGroup... elements

Change-Id: Id1b600999d2051eff8d2207db8235ad08eb6e663
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-05-17 20:03:57 +02:00
parent 0793b945f3
commit 56fda87389
2 changed files with 12 additions and 50 deletions

View File

@@ -990,14 +990,14 @@ void TaskNode::invokeEndHandler(bool success)
qDebug() << "Entering the group"; qDebug() << "Entering the group";
}; };
const Group root { const Group root {
OnGroupSetup(onSetup), onGroupSetup(onSetup),
ProcessTask(...) ProcessTask(...)
}; };
\endcode \endcode
The group setup handler is optional. To define a group setup handler, add an The group setup handler is optional. To define a group setup handler, add an
OnGroupSetup element to a group. The argument of OnGroupSetup is a user onGroupSetup element to a group. The argument of onGroupSetup is a user
handler. If you add more than one OnGroupSetup element to a group, an assert handler. If you add more than one onGroupSetup element to a group, an assert
is triggered at runtime that includes an error message. is triggered at runtime that includes an error message.
Like the task start handler, the group start handler may return TaskAction. Like the task start handler, the group start handler may return TaskAction.
@@ -1011,17 +1011,17 @@ void TaskNode::invokeEndHandler(bool success)
\code \code
const Group root { const Group root {
OnGroupSetup([] { qDebug() << "Root setup"; }), onGroupSetup([] { qDebug() << "Root setup"; }),
Group { Group {
OnGroupSetup([] { qDebug() << "Group 1 setup"; return TaskAction::Continue; }), onGroupSetup([] { qDebug() << "Group 1 setup"; return TaskAction::Continue; }),
ProcessTask(...) // Process 1 ProcessTask(...) // Process 1
}, },
Group { Group {
OnGroupSetup([] { qDebug() << "Group 2 setup"; return TaskAction::StopWithDone; }), onGroupSetup([] { qDebug() << "Group 2 setup"; return TaskAction::StopWithDone; }),
ProcessTask(...) // Process 2 ProcessTask(...) // Process 2
}, },
Group { Group {
OnGroupSetup([] { qDebug() << "Group 3 setup"; return TaskAction::StopWithError; }), onGroupSetup([] { qDebug() << "Group 3 setup"; return TaskAction::StopWithError; }),
ProcessTask(...) // Process 3 ProcessTask(...) // Process 3
}, },
ProcessTask(...) // Process 4 ProcessTask(...) // Process 4
@@ -1080,20 +1080,20 @@ void TaskNode::invokeEndHandler(bool success)
execution of its tasks, respectively. The final value reported by the execution of its tasks, respectively. The final value reported by the
group depends on its \l {Workflow Policy}. The handlers can apply other group depends on its \l {Workflow Policy}. The handlers can apply other
necessary actions. The done and error handlers are defined inside the necessary actions. The done and error handlers are defined inside the
OnGroupDone and OnGroupError elements of a group, respectively. They do not onGroupDone and onGroupError elements of a group, respectively. They do not
take arguments: take arguments:
\code \code
const Group root { const Group root {
OnGroupSetup([] { qDebug() << "Root setup"; }), onGroupSetup([] { qDebug() << "Root setup"; }),
ProcessTask(...), ProcessTask(...),
OnGroupDone([] { qDebug() << "Root finished with success"; }), onGroupDone([] { qDebug() << "Root finished with success"; }),
OnGroupError([] { qDebug() << "Root finished with error"; }) onGroupError([] { qDebug() << "Root finished with error"; })
}; };
\endcode \endcode
The group done and error handlers are optional. If you add more than one The group done and error handlers are optional. If you add more than one
OnGroupDone or OnGroupError each to a group, an assert is triggered at onGroupDone or onGroupError each to a group, an assert is triggered at
runtime that includes an error message. runtime that includes an error message.
\note Even if the group setup handler returns StopWithDone or StopWithError, \note Even if the group setup handler returns StopWithDone or StopWithError,

View File

@@ -259,44 +259,6 @@ public:
Workflow(WorkflowPolicy policy) : TaskItem(policy) {} Workflow(WorkflowPolicy policy) : TaskItem(policy) {}
}; };
class TASKING_EXPORT OnGroupSetup : public TaskItem
{
public:
template <typename SetupFunction>
OnGroupSetup(SetupFunction &&function)
: TaskItem({wrapSetup(std::forward<SetupFunction>(function))}) {}
private:
template<typename SetupFunction>
static TaskItem::GroupSetupHandler wrapSetup(SetupFunction &&function) {
static constexpr bool isDynamic = std::is_same_v<TaskAction,
std::invoke_result_t<std::decay_t<SetupFunction>>>;
constexpr bool isVoid = std::is_same_v<void,
std::invoke_result_t<std::decay_t<SetupFunction>>>;
static_assert(isDynamic || isVoid,
"Group setup handler needs to take no arguments and has to return "
"void or TaskAction. The passed handler doesn't fulfill these requirements.");
return [=] {
if constexpr (isDynamic)
return std::invoke(function);
std::invoke(function);
return TaskAction::Continue;
};
};
};
class TASKING_EXPORT OnGroupDone : public TaskItem
{
public:
OnGroupDone(const GroupEndHandler &handler) : TaskItem({{}, handler}) {}
};
class TASKING_EXPORT OnGroupError : public TaskItem
{
public:
OnGroupError(const GroupEndHandler &handler) : TaskItem({{}, {}, handler}) {}
};
// Synchronous invocation. Similarly to Group - isn't counted as a task inside taskCount() // Synchronous invocation. Similarly to Group - isn't counted as a task inside taskCount()
class TASKING_EXPORT Sync : public Group class TASKING_EXPORT Sync : public Group
{ {