Boost logo

Boost Users :

From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2020-10-19 10:53:23


On 18/10/2020 22:55, Gavin Lambert via Boost-users wrote:
> On 17/10/2020 05:45, David Frank wrote:
>> Does boost promise/future support coroutines?
>>
> Futures and coroutines aren't really a great fit together, since the
> former only has a blocking interface while the latter is intended to be
> used in an entirely non-blocking fashion.

The OP probably was asking if Boost's futures have the coroutines markup
to make them into C++ Coroutine awaitables, like std::future is in MSVC
only.

>From a quick search of
https://www.boost.org/doc/libs/1_74_0/boost/thread/future.hpp, the
answer is no. HOWEVER Boost.Thread's futures do implement .then(), and
via that the additional coroutine markup needed is trivially easy.

(In fact, someone ought to implement that markup if __cpp_coroutines
defined and submit it as a PR, because it's certainly very convenient,
albeit quite inefficient)

> If you're wanting to work with C++20 style coroutines, probably your
> best bet is to use a library such as CppCoro.  While this doesn't have a
> "future" class per se, it does have the equivalent async version as
> "task", and it's possible to do sync waits or wrap it in a future if you
> do want to block a thread for some reason.

We've moved on from task<T> :)

We now have (probably) eager<T> and lazy<T>. Boost.Outcome has
implementations which work just fine with T's having nothing to do with
Outcome.

If the OP wants to resume coroutines on different kernel threads to
where they were suspended, then they'll need to use atomic_eager<T> and
atomic_lazy<T> instead.

https://www.boost.org/doc/libs/develop/libs/outcome/doc/html/reference/types/awaitables/eager.html

https://www.boost.org/doc/libs/develop/libs/outcome/doc/html/reference/types/awaitables/lazy.html

Niall


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net