Details
-
Suggestion
-
Resolution: Unresolved
-
P1: Critical
-
None
-
None
-
None
-
-
13
-
Foundation PM Prioritized
Description
It would be very useful if QFuture could be used without threads to implement lazy evaluation or to fulfill promises asynchronously in the event loop, such as in this example provided by timblechmann:
QObject context; auto promise = QPromise<int>(); promise.future().then(&context, [](int fortytwo) { qDebug() << fortytwo; }); QTimer::singleShot(100ms, [promise = std::move(promise)]() mutable { promise.start(); promise.addResult(42); promise.finish(); });
Unfortunately, FEATURE_future depends on FEATURE_thread, which prevents using QFuture, for example, with WebAssembly (single-threaded).
According to fabiankosmale this will require:
- do a fine-grained removal of API that only works with threads, and you also need to consider what e.g. QFuture::then or waitForFinished should do without threads available
- You would probably need another backend implementation, as the current implementation is tied to threading support (e.g. because it uses QWaitCondition).
The first usecase for this is to improve sample handling in QtMultimedia, see QSampleCache: use promises to simplify object connections (581826) · Gerrit Code Review (qt-project.org)
Attachments
Issue Links
- is required for
-
QTBUG-129465 Simplify QSampleCache threading
- Reported
- relates to
-
QTBUG-35137 Make QFuture usable beyond concurrent framework, add QPromise, QError
- Reported
Gerrit Reviews
For Gerrit Dashboard: QTBUG-129459 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
598772,2 | wip: qfuture: look away, no threads | dev | qt/qtbase | Status: NEW | -2 | 0 |