summaryrefslogtreecommitdiffstats
path: root/src/concurrent
diff options
context:
space:
mode:
authorVitaly Fanaskov <vitaly.fanaskov@qt.io>2020-03-31 11:22:02 +0200
committerVitaly Fanaskov <vitaly.fanaskov@qt.io>2020-04-14 17:44:13 +0200
commit678b9f78a5af4513ed4e988de90148584a2ae90d (patch)
tree090b7970c739396d20a758bd87280b13ee9159cf /src/concurrent
parentc028cbccc248581ca37389fa50e02a988d006348 (diff)
QTaskBuilder::spawn: add an overload that doesn't return a future object
Fixes: QTBUG-83175 Change-Id: Idf85e47a2732742884272200d5c753805eaa640b Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/concurrent')
-rw-r--r--src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp4
-rw-r--r--src/concurrent/qtaskbuilder.h12
-rw-r--r--src/concurrent/qtaskbuilder.qdoc19
-rw-r--r--src/concurrent/qtconcurrenttask.qdoc5
4 files changed, 40 insertions, 0 deletions
diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp
index bec45ba3bf..b067b49e7e 100644
--- a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp
+++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp
@@ -125,3 +125,7 @@ QtConcurrent::task([]{ return 42; }).onThreadPool(pool).spawn();
//! [10]
QtConcurrent::task([]{ return 42; }).withPriority(10).spawn();
//! [10]
+
+//! [11]
+QtConcurrent::task([]{ qDebug("Hello, world!"); }).spawn(FutureResult::Ignore);
+//! [11]
diff --git a/src/concurrent/qtaskbuilder.h b/src/concurrent/qtaskbuilder.h
index 5fc2bccfb5..074dad1c6b 100644
--- a/src/concurrent/qtaskbuilder.h
+++ b/src/concurrent/qtaskbuilder.h
@@ -52,6 +52,8 @@ QT_BEGIN_NAMESPACE
namespace QtConcurrent {
+enum class FutureResult { Ignore };
+
using InvokeResultType = int;
template <class Task, class ...Args>
@@ -61,6 +63,8 @@ public:
[[nodiscard]]
QFuture<InvokeResultType> spawn();
+ void spawn(FutureResult);
+
template <class ...ExtraArgs>
[[nodiscard]]
QTaskBuilder<Task, ExtraArgs...> withArguments(ExtraArgs &&...args);
@@ -78,6 +82,8 @@ public:
namespace QtConcurrent {
+enum class FutureResult { Ignore };
+
template <class Task, class ...Args>
class QTaskBuilder
{
@@ -89,6 +95,12 @@ public:
->start(startParameters);
}
+ void spawn(FutureResult)
+ {
+ (new StoredFunctionCall<Task, Args...>(std::move(taskWithArgs)))
+ ->start(startParameters);
+ }
+
template <class ...ExtraArgs>
[[nodiscard]]
constexpr auto withArguments(ExtraArgs &&...args)
diff --git a/src/concurrent/qtaskbuilder.qdoc b/src/concurrent/qtaskbuilder.qdoc
index 8352cae17a..1340307806 100644
--- a/src/concurrent/qtaskbuilder.qdoc
+++ b/src/concurrent/qtaskbuilder.qdoc
@@ -45,6 +45,13 @@
*/
/*!
+ \fn template <class Task, class ...Args> void QtConcurrent::QTaskBuilder<Task, Args...>::spawn(QtConcurrent::FutureResult)
+
+ Runs the task in a separate thread. This is a non-blocking call.
+ The task might not start immediately.
+*/
+
+/*!
\fn template <class Task, class ...Args> template <class ...ExtraArgs> [[nodiscard]] QTaskBuilder<Task, ExtraArgs...> QtConcurrent::QTaskBuilder<Task, Args...>::withArguments(ExtraArgs &&...args)
Sets the arguments \a args the task will be invoked with. The code is ill-formed
@@ -80,3 +87,15 @@
The real implementation also contains a compile-time check for
whether the task can be invoked with the specified arguments or not.
*/
+
+/*!
+ \enum QtConcurrent::FutureResult
+
+ This enum type is used to invoke a special overload of
+ QtConcurrent::QTaskBuilder::spawn(QtConcurrent::FutureResult)
+ that doesn't return a future object.
+
+ \value Ignore
+ An auxiliary tag which introduced to improve code
+ readability.
+*/
diff --git a/src/concurrent/qtconcurrenttask.qdoc b/src/concurrent/qtconcurrenttask.qdoc
index e25e485bd1..9000b424fe 100644
--- a/src/concurrent/qtconcurrenttask.qdoc
+++ b/src/concurrent/qtconcurrenttask.qdoc
@@ -143,6 +143,11 @@
You can set the priority for a task:
\snippet code/src_concurrent_qtconcurrenttask.cpp 10
+
+ If you don't need a future object, you can call
+ QtConcurrent::QTaskBuilder::spawn(QtConcurrent::FutureResult::Ignore):
+
+ \snippet code/src_concurrent_qtconcurrenttask.cpp 11
*/
/*!