forked from qt-creator/qt-creator
TaskTree: Remove timeout arg from runBlocking() methods
The timeout may be passed via .withTimeout() method. Change-Id: I7235a2c46836b63796024a3801225709e7835aa2 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -3274,9 +3274,6 @@ DoneWith TaskTree::runBlocking(const QFuture<void> &future)
|
|||||||
/*!
|
/*!
|
||||||
Constructs a temporary task tree using the passed \a recipe and runs it blocking.
|
Constructs a temporary task tree using the passed \a recipe and runs it blocking.
|
||||||
|
|
||||||
The optionally provided \a timeout is used to cancel the tree automatically after
|
|
||||||
\a timeout milliseconds have passed.
|
|
||||||
|
|
||||||
Returns DoneWith::Success if the task tree finished successfully;
|
Returns DoneWith::Success if the task tree finished successfully;
|
||||||
otherwise returns DoneWith::Error.
|
otherwise returns DoneWith::Error.
|
||||||
|
|
||||||
@@ -3285,24 +3282,22 @@ DoneWith TaskTree::runBlocking(const QFuture<void> &future)
|
|||||||
|
|
||||||
\sa start()
|
\sa start()
|
||||||
*/
|
*/
|
||||||
DoneWith TaskTree::runBlocking(const Group &recipe, milliseconds timeout)
|
DoneWith TaskTree::runBlocking(const Group &recipe)
|
||||||
{
|
{
|
||||||
QPromise<void> dummy;
|
QPromise<void> dummy;
|
||||||
dummy.start();
|
dummy.start();
|
||||||
return TaskTree::runBlocking(recipe, dummy.future(), timeout);
|
return TaskTree::runBlocking(recipe, dummy.future());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\overload runBlocking(const Group &recipe, milliseconds timeout)
|
\overload runBlocking(const Group &recipe)
|
||||||
|
|
||||||
The passed \a future is used for listening to the cancel event.
|
The passed \a future is used for listening to the cancel event.
|
||||||
When the task tree is canceled, this method cancels the passed \a future.
|
When the task tree is canceled, this method cancels the passed \a future.
|
||||||
*/
|
*/
|
||||||
DoneWith TaskTree::runBlocking(const Group &recipe, const QFuture<void> &future, milliseconds timeout)
|
DoneWith TaskTree::runBlocking(const Group &recipe, const QFuture<void> &future)
|
||||||
{
|
{
|
||||||
const Group root = timeout == milliseconds::max() ? recipe
|
TaskTree taskTree(recipe);
|
||||||
: Group { recipe.withTimeout(timeout) };
|
|
||||||
TaskTree taskTree(root);
|
|
||||||
return taskTree.runBlocking(future);
|
return taskTree.runBlocking(future);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -633,10 +633,8 @@ public:
|
|||||||
// Don't use it in main thread. To be used in non-main threads or in auto tests.
|
// Don't use it in main thread. To be used in non-main threads or in auto tests.
|
||||||
DoneWith runBlocking();
|
DoneWith runBlocking();
|
||||||
DoneWith runBlocking(const QFuture<void> &future);
|
DoneWith runBlocking(const QFuture<void> &future);
|
||||||
static DoneWith runBlocking(const Group &recipe,
|
static DoneWith runBlocking(const Group &recipe);
|
||||||
std::chrono::milliseconds timeout = std::chrono::milliseconds::max());
|
static DoneWith runBlocking(const Group &recipe, const QFuture<void> &future);
|
||||||
static DoneWith runBlocking(const Group &recipe, const QFuture<void> &future,
|
|
||||||
std::chrono::milliseconds timeout = std::chrono::milliseconds::max());
|
|
||||||
|
|
||||||
int asyncCount() const;
|
int asyncCount() const;
|
||||||
int taskCount() const;
|
int taskCount() const;
|
||||||
|
@@ -475,15 +475,14 @@ void FileSystemAccessTest::testFileStreamer()
|
|||||||
const auto onReaderDone = [result](const FileStreamer &streamer) {
|
const auto onReaderDone = [result](const FileStreamer &streamer) {
|
||||||
*result = streamer.readData();
|
*result = streamer.readData();
|
||||||
};
|
};
|
||||||
const Group root {
|
return Group {
|
||||||
FileStreamerTask(onTransferSetup),
|
FileStreamerTask(onTransferSetup),
|
||||||
FileStreamerTask(onReaderSetup, onReaderDone, CallDoneIf::Success)
|
FileStreamerTask(onReaderSetup, onReaderDone, CallDoneIf::Success)
|
||||||
};
|
};
|
||||||
return root;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// In total: 5 local reads, 3 local writes, 5 remote reads, 3 remote writes
|
// In total: 5 local reads, 3 local writes, 5 remote reads, 3 remote writes
|
||||||
const Group root {
|
const Group recipe {
|
||||||
Group {
|
Group {
|
||||||
parallel,
|
parallel,
|
||||||
localWriter(),
|
localWriter(),
|
||||||
@@ -504,7 +503,7 @@ void FileSystemAccessTest::testFileStreamer()
|
|||||||
};
|
};
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
QCOMPARE(TaskTree::runBlocking(root, 10000ms), DoneWith::Success);
|
QCOMPARE(TaskTree::runBlocking(recipe.withTimeout(10000ms)), DoneWith::Success);
|
||||||
|
|
||||||
QVERIFY(localData);
|
QVERIFY(localData);
|
||||||
QCOMPARE(*localData, data);
|
QCOMPARE(*localData, data);
|
||||||
|
@@ -482,15 +482,14 @@ void tst_Async::taskTree()
|
|||||||
value = task.result();
|
value = task.result();
|
||||||
};
|
};
|
||||||
|
|
||||||
const Group root {
|
const Group recipe {
|
||||||
AsyncTask<int>(setupIntAsync, handleIntAsync, CallDoneIf::Success),
|
AsyncTask<int>(setupIntAsync, handleIntAsync, CallDoneIf::Success),
|
||||||
AsyncTask<int>(setupIntAsync, handleIntAsync, CallDoneIf::Success),
|
AsyncTask<int>(setupIntAsync, handleIntAsync, CallDoneIf::Success),
|
||||||
AsyncTask<int>(setupIntAsync, handleIntAsync, CallDoneIf::Success),
|
AsyncTask<int>(setupIntAsync, handleIntAsync, CallDoneIf::Success),
|
||||||
AsyncTask<int>(setupIntAsync, handleIntAsync, CallDoneIf::Success),
|
AsyncTask<int>(setupIntAsync, handleIntAsync, CallDoneIf::Success),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QCOMPARE(TaskTree::runBlocking(recipe.withTimeout(1000ms)), DoneWith::Success);
|
||||||
QCOMPARE(TaskTree::runBlocking(root, 1000ms), DoneWith::Success);
|
|
||||||
QCOMPARE(value, 16);
|
QCOMPARE(value, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,7 +510,7 @@ void tst_Async::mapReduce_data()
|
|||||||
{
|
{
|
||||||
using namespace Tasking;
|
using namespace Tasking;
|
||||||
|
|
||||||
QTest::addColumn<Group>("root");
|
QTest::addColumn<Group>("recipe");
|
||||||
QTest::addColumn<double>("sum");
|
QTest::addColumn<double>("sum");
|
||||||
QTest::addColumn<QList<double>>("results");
|
QTest::addColumn<QList<double>>("results");
|
||||||
|
|
||||||
@@ -622,11 +621,11 @@ void tst_Async::mapReduce()
|
|||||||
|
|
||||||
using namespace Tasking;
|
using namespace Tasking;
|
||||||
|
|
||||||
QFETCH(Group, root);
|
QFETCH(Group, recipe);
|
||||||
QFETCH(double, sum);
|
QFETCH(double, sum);
|
||||||
QFETCH(QList<double>, results);
|
QFETCH(QList<double>, results);
|
||||||
|
|
||||||
QCOMPARE(TaskTree::runBlocking(root, 1000ms), DoneWith::Success);
|
QCOMPARE(TaskTree::runBlocking(recipe.withTimeout(1000ms)), DoneWith::Success);
|
||||||
QCOMPARE(s_results, results);
|
QCOMPARE(s_results, results);
|
||||||
QCOMPARE(s_sum, sum);
|
QCOMPARE(s_sum, sum);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user