summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qfuture.h
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-04-06 13:03:12 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2022-04-21 20:25:13 +0000
commit9eb090d6835e436627c7a6b00e2ee97933847345 (patch)
tree0a5c210d0a39982648f0bde721141ad6d628b2d1 /src/corelib/thread/qfuture.h
parentf08fd3c05565f8cb170b0314a891bc1b515196e8 (diff)
Add support for unwrapping QFuture<QFuture<T>>
Added QFuture::unwrap() for unwrapping the future nested inside QFuture<QFuture<T>>. QTBUG-86725 suggests doing the unwrapping automatically inside .then(), but this will change the return type of .then() that used to return QFuture<QFuture<T>> and might cause SC breaks. Apart from that, QFuture::unwrap() might be helpful in general, for asynchronous computations that return a nested QFuture. [ChangeLog][QtCore][QFuture] Added QFuture::unwrap() for unwrapping the future nested inside QFuture<QFuture<T>>. Task-number: QTBUG-86725 Change-Id: I8886743aca261dca46f62d9dfcaead4a141d3dc4 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/thread/qfuture.h')
-rw-r--r--src/corelib/thread/qfuture.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h
index 7aed38be16..c450221769 100644
--- a/src/corelib/thread/qfuture.h
+++ b/src/corelib/thread/qfuture.h
@@ -191,6 +191,14 @@ QT_WARNING_POP
template<class Function, typename = std::enable_if_t<std::is_invocable_r_v<T, Function>>>
QFuture<T> onCanceled(QObject *context, Function &&handler);
+#if !defined(Q_CLANG_QDOC)
+ template<class U = T, typename = std::enable_if_t<QtPrivate::isQFutureV<U>>>
+ auto unwrap();
+#else
+ template<class U>
+ QFuture<U> unwrap();
+#endif
+
class const_iterator
{
public:
@@ -317,6 +325,8 @@ private:
template<typename ResultType>
friend struct QtPrivate::WhenAnyContext;
+ friend struct QtPrivate::UnwrapHandler;
+
using QFuturePrivate =
std::conditional_t<std::is_same_v<T, void>, QFutureInterfaceBase, QFutureInterface<T>>;
@@ -431,6 +441,16 @@ QFuture<T> QFuture<T>::onCanceled(QObject *context, Function &&handler)
return promise.future();
}
+template<class T>
+template<class U, typename>
+auto QFuture<T>::unwrap()
+{
+ if constexpr (QtPrivate::isQFutureV<typename QtPrivate::Future<T>::type>)
+ return QtPrivate::UnwrapHandler::unwrapImpl(this).unwrap();
+ else
+ return QtPrivate::UnwrapHandler::unwrapImpl(this);
+}
+
inline QFuture<void> QFutureInterface<void>::future()
{
return QFuture<void>(this);