diff options
| author | Ivan Solovev <ivan.solovev@qt.io> | 2025-11-04 15:25:11 +0100 |
|---|---|---|
| committer | Ivan Solovev <ivan.solovev@qt.io> | 2025-12-04 18:59:04 +0100 |
| commit | 9d6828e9257325b011352a6d6d1a1e0da62f976b (patch) | |
| tree | df52a47ca3ed72c473e874c5da3fd0bf1995619f /src/corelib/doc/snippets | |
| parent | eecc41edcaa85a39c5981e9813a33fc8392f7cd3 (diff) | |
Document QFuture::cancelChain() limitations
Explicitly mention that cancelChain() cannot cancel a nested QFuture
once the related computation has started. The user needs to explicitly
capture and cancel the nested future instead.
Task-number: QTBUG-140786
Pick-to: 6.10
Change-Id: Icc629071659a5833f7e9b55c640fd9920b6bd8a9
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
| -rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp | 24 |
1 files changed, 24 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 |
