[Development] QtCS2024 QFuture/QPromise
Mårten Nordheim
marten.nordheim at qt.io
Fri Sep 6 16:21:56 CEST 2024
Hey all,
Hope you all had a good time at QtCS so far.
Anyway, I was reading through some of the notes. I have looked at QFuture some on my own too...
QFuture is quite alright when used for its intended purpose - GUI. Other than that it's too magical.
It let's you read results as-they-come, which is great when you are populating a GUI as the results
come in.
But for a normal use-case this "maybe there are multiple results" makes it terrible to interface with
generically.
Specifically making it awaitable for the sake of coroutines:
```
QFuture<int> future;
auto result = co_await future;
```
What is decltype(result) here? It should be the type that the QFuture has 'promised'.
But do we make it QList<int> _just in case_ there are multiple results added?
Given all coroutines would return 1 value, while most QtConcurrent operations
could return lists, it's not an easy answer.
Not being able to answer this at compile-time means, IMO, it can't _generically_ be made awaitable
and we are far better off introducing a new type, like QTask or similar, with a smaller interface,
for use with coroutines and other generic code.
Mårten
More information about the Development
mailing list