futures/adaptor/when_all.hpp
Conjunction adaptors.
#include <futures/adaptor/when_all.hpp>
Namespaces
Name | Description |
---|---|
futures | Main library namespace. |
Classes
Classes | Description |
---|---|
when_all_future | Proxy future class referring to a conjunction of futures from when_all. (class) |
Description
This file defines adaptors to create a new future representing the conjunction of other future objects.
Because all tasks need to be done to achieve the result, the algorithm doesn't depend much on the properties of the underlying futures. The thread that is awaiting just needs sleep and await for each of the internal futures.
The usual approach, without our future concepts, like in returning another std::future, is to start another polling thread, which sets a promise when all other futures are ready. If the futures support lazy continuations, these promises can be set from the previous objects. However, this has an obvious cost for such a trivial operation, given that the solutions is already available in the underlying futures.
Instead, we implement one more future type when_all_future
that can query if the futures are ready and waits for them to be ready whenever get() is called. This proxy object can then be converted to a regular future if the user needs to.
This has a disadvantage over futures with lazy continuations because we might need to schedule another task if we need notifications from this future. However, we avoid scheduling another task right now, so this is, at worst, as good as the common approach of wrapping it into another existing future type.
If the input futures are not shared, they are moved into when_all_future
and are invalidated, as usual. The when_all_future
cannot be shared.
Updated on 2023-01-04