cobalt
cobalt copied to clipboard
added composed.
Downgrading to draft. We'll need internal use-cases to make this relevant.
here is what I am now thinking:
extern promise<int> dummy();
composition<error_code, size_t> compost(asio::ip::tcp::socket & sock) // take the executor from the first argument, also works if it's this!
{
auto [ec, n] = co_await sock.async_read_some(sock, ...); // automatically apply as_tuple, to discourage exceptions being thrown!
auto [ex, i] = co_await dummy(); // ex-ptr here
co_return {ec, n}; // complete
}
so let's say we have
extern composition<error_code, mysql::resultset> mysql::query(mysql::connection & conn, string_view query);
// in promise:
auto rs = co_await mysql::query(conn, "select * from cities"); // throws
auto [ec, rr] = co_await cobalt::as_tuple(mysql::query(conn, "select * from cities")); // now you get the ec instead of an ep here