summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp24
-rw-r--r--src/corelib/thread/qfuture.qdoc14
2 files changed, 38 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
index 6531d025bef..89ac917ccd3 100644
--- a/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
@@ -543,6 +543,30 @@ void examples(QFuture<QString> someQStringFuture,
f.cancelChain();
//! [38]
}
+
+ {
+ auto createFuture = [] { return QtFuture::makeReadyVoidFuture(); };
+ auto runNestedComputation = [] { return QtFuture::makeReadyVoidFuture(); };
+ //! [39]
+ QFuture<void> nested;
+ auto f = createFuture()
+ .then([&]{
+ nested = runNestedComputation();
+ // do some other work
+ return nested;
+ })
+ .unwrap()
+ .then([]{
+ // other continuation
+ })
+ .onCanceled([]{
+ // handle cancellation
+ });
+ //...
+ f.cancelChain();
+ nested.cancel();
+ //! [39]
+ }
}
class SomeClass : public QObject
diff --git a/src/corelib/thread/qfuture.qdoc b/src/corelib/thread/qfuture.qdoc
index c4d4daae99f..f3f32e20adc 100644
--- a/src/corelib/thread/qfuture.qdoc
+++ b/src/corelib/thread/qfuture.qdoc
@@ -215,6 +215,20 @@
It's recommended to use it on the QFuture object that represents the entire
continuation chain, like it's shown in the example above.
+ If any of the continuations in the chain executes an asynchronous
+ computation and returns a QFuture representing it, the \c cancelChain() call
+ will not be propagated into such nested computation once it is started.
+ The reason for that is that the future will be available in the continuation
+ chain only when the outer future is fulfilled, but the cancellation might
+ happen when both an outer and a nested futures are still waiting for their
+ computations to be finished. In such cases, the nested future needs to be
+ captured and canceled explicitly.
+
+ \snippet code/src_corelib_thread_qfuture.cpp 39
+
+ In this example, if \c runNestedComputation() is already in progress,
+ it can only be canceled by calling \c {nested.cancel()}.
+
\sa cancel()
*/