-
-
Notifications
You must be signed in to change notification settings - Fork 70
Support for move only types in QFuture via takeResult #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
danvratil
added a commit
that referenced
this issue
Apr 22, 2024
We already have QCoroFuture::waitForFinished(), which is an async version of QFuture::waitForFinished() (but also returns the result, unlike QFuture::waitForFinished) - it's basically a combination of QFuture::waitForFinished() + QFuture::result()). In Qt 6 there's also QFuture::takeResult() which moves the result from the QFuture to the caller. This change introduces QCoroFuture::takeResult(), which is an asynchronous equivalent to QFuture::waitForFinished() + QFuture::takeResult()). To make the API more symmetrical, this change also introduces QCoroFuture::result(), which is equivalent to waitForFinished(), but it's now clearer that result() returns copy, while takeResult() moves (like their QFuture counterparts). waitForFinished() is still available but discouraged for newly written code in favor of result() (or directly co_awaiting on QFuture object).
danvratil
added a commit
that referenced
this issue
Apr 22, 2024
We already have QCoroFuture::waitForFinished(), which is an async version of QFuture::waitForFinished() (but also returns the result, unlike QFuture::waitForFinished) - it's basically a combination of QFuture::waitForFinished() + QFuture::result()). In Qt 6 there's also QFuture::takeResult() which moves the result from the QFuture to the caller. This change introduces QCoroFuture::takeResult(), which is an asynchronous equivalent to QFuture::waitForFinished() + QFuture::takeResult()). To make the API more symmetrical, this change also introduces QCoroFuture::result(), which is equivalent to waitForFinished(), but it's now clearer that result() returns copy, while takeResult() moves (like their QFuture counterparts). waitForFinished() is still available but discouraged for newly written code in favor of result() (or directly co_awaiting on QFuture object).
danvratil
added a commit
that referenced
this issue
Apr 22, 2024
Implement QCoroFuture::takeResult (fixes #217)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Qt 6.0 added
QFuture::takeResult
which allows using move only types with futures, as long as you only get the result once.QCoroFuture
usesresult
, which I believe is the correct default, but I would like a way to opt into using the move version.As a hack I just took
QCoroFuture
and modified it a bit, and this works great. Maybe something likeco_await QCoroFutureOnce(future)
would work, or maybeco_await qCoro(future).moveable()
.The text was updated successfully, but these errors were encountered: