forked from qt-creator/qt-creator
TaskTree: Get rid of the fluent interface
It wasn't really used and it interferes when refactoring. Change-Id: I8b8ba1740fef24502855e896e9b33ba816e1229f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -452,53 +452,6 @@ private:
|
||||
When the running task finishes, one of \a done or \a error handlers is called,
|
||||
depending on whether it finished with success or an error, respectively.
|
||||
Both handlers are of std::function<void(const Task &)> type.
|
||||
|
||||
\sa onSetup(), onDone(), onError()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Adapter> template <typename SetupHandler> CustomTask<Adapter> &CustomTask<Adapter>::onSetup(SetupHandler &&handler)
|
||||
|
||||
Attaches the setup \a handler to \c this task.
|
||||
The \a handler is invoked when the task is about to be started.
|
||||
|
||||
This function enables defining the task's details with a
|
||||
\l {https://en.wikipedia.org/wiki/Fluent_interface}{fluent interface} style:
|
||||
|
||||
\code
|
||||
const auto onQuerySetup = [](NetworkQuery &task) { ... };
|
||||
const auto onQueryError = [](const NetworkQuery &task) { ... };
|
||||
|
||||
const Group group {
|
||||
NetworkQueryTask(onQuerySetup, {}, onQueryError),
|
||||
NetworkQueryTask().onSetup(onQuerySetup).onError(onQueryError), // fluent interface style
|
||||
NetworkQueryTask(onQuerySetup, {}, onQueryError).withTimeout(500ms)
|
||||
}
|
||||
\endcode
|
||||
|
||||
\sa CustomTask(), onDone(), onError()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Adapter> CustomTask<Adapter> &CustomTask<Adapter>::onDone(const EndHandler &handler)
|
||||
|
||||
Attaches the done \a handler to \c this task.
|
||||
The handler is invoked when the task finishes with success.
|
||||
|
||||
This function enables defining the task's details with a fluent interface style.
|
||||
|
||||
\sa CustomTask(), onSetup(), onError()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Adapter> CustomTask<Adapter> &CustomTask<Adapter>::onError(const EndHandler &handler)
|
||||
|
||||
Attaches the error \a handler to \c this task.
|
||||
The handler is invoked when the task finishes with an error.
|
||||
|
||||
This function enables defining the task's details with a fluent interface style.
|
||||
|
||||
\sa CustomTask(), onSetup(), onDone()
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -511,8 +464,6 @@ private:
|
||||
the returned item finishes immediately with the task's result.
|
||||
Otherwise, the \a handler is invoked (if provided), the task is stopped,
|
||||
and the returned item finishes with an error.
|
||||
|
||||
\sa onSetup()
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -1002,39 +953,6 @@ void GroupItem::addChildren(const QList<GroupItem> &children)
|
||||
}
|
||||
}
|
||||
|
||||
void GroupItem::setTaskSetupHandler(const TaskSetupHandler &handler)
|
||||
{
|
||||
if (!handler) {
|
||||
qWarning("Setting empty Setup Handler is no-op, skipping...");
|
||||
return;
|
||||
}
|
||||
if (m_taskHandler.m_setupHandler)
|
||||
qWarning("Setup Handler redefinition, overriding...");
|
||||
m_taskHandler.m_setupHandler = handler;
|
||||
}
|
||||
|
||||
void GroupItem::setTaskDoneHandler(const TaskEndHandler &handler)
|
||||
{
|
||||
if (!handler) {
|
||||
qWarning("Setting empty Done Handler is no-op, skipping...");
|
||||
return;
|
||||
}
|
||||
if (m_taskHandler.m_doneHandler)
|
||||
qWarning("Done Handler redefinition, overriding...");
|
||||
m_taskHandler.m_doneHandler = handler;
|
||||
}
|
||||
|
||||
void GroupItem::setTaskErrorHandler(const TaskEndHandler &handler)
|
||||
{
|
||||
if (!handler) {
|
||||
qWarning("Setting empty Error Handler is no-op, skipping...");
|
||||
return;
|
||||
}
|
||||
if (m_taskHandler.m_errorHandler)
|
||||
qWarning("Error Handler redefinition, overriding...");
|
||||
m_taskHandler.m_errorHandler = handler;
|
||||
}
|
||||
|
||||
GroupItem GroupItem::withTimeout(const GroupItem &item, milliseconds timeout,
|
||||
const GroupEndHandler &handler)
|
||||
{
|
||||
|
||||
@@ -189,9 +189,6 @@ protected:
|
||||
, m_taskHandler(handler) {}
|
||||
void addChildren(const QList<GroupItem> &children);
|
||||
|
||||
void setTaskSetupHandler(const TaskSetupHandler &handler);
|
||||
void setTaskDoneHandler(const TaskEndHandler &handler);
|
||||
void setTaskErrorHandler(const TaskEndHandler &handler);
|
||||
static GroupItem groupHandler(const GroupHandler &handler) { return GroupItem({handler}); }
|
||||
static GroupItem parallelLimit(int limit) { return GroupItem({{}, limit}); }
|
||||
static GroupItem workflowPolicy(WorkflowPolicy policy) { return GroupItem({{}, {}, policy}); }
|
||||
@@ -336,20 +333,6 @@ public:
|
||||
: GroupItem({&createAdapter, wrapSetup(std::forward<SetupHandler>(setup)),
|
||||
wrapEnd(done), wrapEnd(error)}) {}
|
||||
|
||||
template <typename SetupHandler>
|
||||
CustomTask &onSetup(SetupHandler &&handler) {
|
||||
setTaskSetupHandler(wrapSetup(std::forward<SetupHandler>(handler)));
|
||||
return *this;
|
||||
}
|
||||
CustomTask &onDone(const EndHandler &handler) {
|
||||
setTaskDoneHandler(wrapEnd(handler));
|
||||
return *this;
|
||||
}
|
||||
CustomTask &onError(const EndHandler &handler) {
|
||||
setTaskErrorHandler(wrapEnd(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
GroupItem withTimeout(std::chrono::milliseconds timeout,
|
||||
const GroupEndHandler &handler = {}) const {
|
||||
return GroupItem::withTimeout(*this, timeout, handler);
|
||||
|
||||
@@ -114,8 +114,6 @@ void tst_Tasking::validConstructs()
|
||||
const auto doneHandler = [](const TaskObject &) {};
|
||||
const auto errorHandler = [](const TaskObject &) {};
|
||||
|
||||
// Not fluent interface
|
||||
|
||||
const Group task2 {
|
||||
parallel,
|
||||
TestTask(setupHandler),
|
||||
@@ -125,20 +123,6 @@ void tst_Tasking::validConstructs()
|
||||
TestTask(setupHandler, {}, errorHandler)
|
||||
};
|
||||
|
||||
// Fluent interface
|
||||
|
||||
const Group fluent {
|
||||
parallel,
|
||||
TestTask().onSetup(setupHandler),
|
||||
TestTask().onSetup(setupHandler).onDone(doneHandler),
|
||||
TestTask().onSetup(setupHandler).onDone(doneHandler).onError(errorHandler),
|
||||
// possible to skip the empty done
|
||||
TestTask().onSetup(setupHandler).onError(errorHandler),
|
||||
// possible to set handlers in a different order
|
||||
TestTask().onError(errorHandler).onDone(doneHandler).onSetup(setupHandler),
|
||||
};
|
||||
|
||||
|
||||
// When turning each of below blocks on, you should see the specific compiler error message.
|
||||
|
||||
#if 0
|
||||
|
||||
Reference in New Issue
Block a user