summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qfuture.h
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2020-03-30 10:46:00 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2020-04-01 21:51:13 +0200
commit0f78e85421de113d73edf0d58b34e12ad188417c (patch)
tree08d12c70cb555c6514d2ad202b79389f9b50f8c4 /src/corelib/thread/qfuture.h
parent495f958b9ac5c45196e743fcba300fcfd25b90a3 (diff)
Add support of failure handler callbacks to QFuture
Added QFuture::onFailed() method, which allows attaching handlers for exceptions that may occur in QFuture continuation chains. Task-number: QTBUG-81588 Change-Id: Iadeee99e3a7573207f6ca9f650ff9f7b6faa2cf7 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/thread/qfuture.h')
-rw-r--r--src/corelib/thread/qfuture.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h
index 0507cfb59e..bfca16b641 100644
--- a/src/corelib/thread/qfuture.h
+++ b/src/corelib/thread/qfuture.h
@@ -162,6 +162,12 @@ public:
template<class Function>
QFuture<ResultType<Function>> then(QThreadPool *pool, Function &&function);
+#ifndef QT_NO_EXCEPTIONS
+ template<class Function,
+ typename = std::enable_if_t<!QtPrivate::ArgResolver<Function>::HasExtraArgs>>
+ QFuture<T> onFailed(Function &&handler);
+#endif
+
class const_iterator
{
public:
@@ -275,6 +281,11 @@ private:
template<class Function, class ResultType, class ParentResultType>
friend class QtPrivate::Continuation;
+#ifndef QT_NO_EXCEPTIONS
+ template<class Function, class ResultType>
+ friend class QtPrivate::FailureHandler;
+#endif
+
using QFuturePrivate =
std::conditional_t<std::is_same_v<T, void>, QFutureInterfaceBase, QFutureInterface<T>>;
@@ -335,6 +346,19 @@ QFuture<typename QFuture<T>::template ResultType<Function>> QFuture<T>::then(QTh
return promise.future();
}
+#ifndef QT_NO_EXCEPTIONS
+
+template<class T>
+template<class Function, typename>
+QFuture<T> QFuture<T>::onFailed(Function &&handler)
+{
+ QFutureInterface<T> promise(QFutureInterfaceBase::State::Pending);
+ QtPrivate::FailureHandler<Function, T>::create(std::forward<Function>(handler), this, promise);
+ return promise.future();
+}
+
+#endif
+
inline QFuture<void> QFutureInterface<void>::future()
{
return QFuture<void>(this);