Is there any experimental or 3rd party library feature, which allows to pass a sequence (or wrapped set) of futures/promises? Consider an example:
struct header {};
struct body {};
struct footer {};
using footer_future = std::future<footer>;
using body_future = std::future<std::tuple<body, footer_future>>;
using page_future = std::future<std::tuple<header, body_future>>;
page_future generate_page() {
// asynchronously generate a page
// and return each piece via a promise right after it is generated
}
int main() {
// unwrapping the sequence of futures.
// next future is available only when successfully got the previous one
auto page_fut = generate_page();
auto [h, body_fut] = page_fut.get();
auto [b, footer_fut] = body_fut.get();
auto f = footer_fut.get();
}
I would imagine it could be something like future_sequence<header, body, footer>
, where get()
returns the next portion.
Or there is some fundamental flaw with this concept?
Although I haven't tried the code, I do not see any fundamental flaw with this.
With some template metaprogramming and variadic you should be able to do that.