8000 Support for move only types in QFuture via takeResult · Issue #217 · qcoro/qcoro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Closed
fluttershydev opened this issue Apr 20, 2024 · 0 comments · Fixed by #218
Closed

Support for move only types in QFuture via takeResult #217

fluttershydev opened this issue Apr 20, 2024 · 0 comments · Fixed by #218

Comments

@fluttershydev
Copy link

Qt 6.0 added QFuture::takeResult which allows using move only types with futures, as long as you only get the result once. QCoroFuture uses result, 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 like co_await QCoroFutureOnce(future) would work, or maybe co_await qCoro(future).moveable().

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 danvratil linked a pull request Apr 22, 2024 that will close this issue
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant
0