danvratil / qcoro

C++ Coroutines for Qt
https://qcoro.dvratil.cz
MIT License
326 stars 53 forks source link

Implement QCoroFuture::takeResult (fixes #217) #218

Closed danvratil closed 4 months ago

danvratil commented 4 months ago

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).