diff --git a/src/corelib/thread/qpromise.h b/src/corelib/thread/qpromise.h index a3ad04648bd..d0f6e6ae66e 100644 --- a/src/corelib/thread/qpromise.h +++ b/src/corelib/thread/qpromise.h @@ -39,7 +39,7 @@ public: // potential waits if (d.d && !(d.loadState() & QFutureInterfaceBase::State::Finished)) { d.cancelAndFinish(); // cancel and finalize the state - d.cleanContinuation(); + d.runContinuation(); } } diff --git a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp index 5de8ce13ab2..12206aa9fc9 100644 --- a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp +++ b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp @@ -40,6 +40,7 @@ private slots: #endif void cancelWhenReassigned(); void cancelWhenDestroyedWithoutStarting(); + void cancelWhenDestroyedRunsContinuations(); void finishWhenSwapped(); void cancelWhenMoved(); void waitUntilResumed(); @@ -494,6 +495,25 @@ void tst_QPromise::cancelWhenDestroyedWithoutStarting() QVERIFY(future.isFinished()); } +void tst_QPromise::cancelWhenDestroyedRunsContinuations() +{ + QFuture future; + bool onCanceledCalled = false; + bool thenCalled = false; + { + QPromise promise; + future = promise.future(); + future.then([&] { + thenCalled = true; + }).onCanceled([&] { + onCanceledCalled = true; + }); + } + QVERIFY(future.isFinished()); + QVERIFY(!thenCalled); + QVERIFY(onCanceledCalled); +} + void tst_QPromise::finishWhenSwapped() { #if !QT_CONFIG(cxx11_future)