PostingPromise: Add dynamic post-to io_context targeting

This allows us to dynamically choose the target that a PostingPromise
coro will be posted to at runtime rather than only posting to the
statically configured ThreadTag::io_context() target. Big usability
improvement.
This commit is contained in:
2026-05-30 20:44:53 -04:00
parent 2749d77d65
commit 42076d6c78
2 changed files with 116 additions and 33 deletions
+29
View File
@@ -0,0 +1,29 @@
#ifndef POST_TARGET_H
#define POST_TARGET_H
#include <type_traits>
#include <boost/asio/io_context.hpp>
namespace sscl::co {
/** Opt-in dynamic post-TO target for TaggedPostingPromise coroutines.
* When omitted, initial_suspend posts to ThreadTag::io_context().
* Post-back still uses callerIoContext (getSelf() at co_await site).
*/
struct ExplicitPostTarget
{
boost::asio::io_context& ioContext;
explicit ExplicitPostTarget(boost::asio::io_context& ctx) noexcept
: ioContext(ctx)
{}
};
template<typename T>
inline constexpr bool is_explicit_post_target_v =
std::same_as<std::remove_cvref_t<T>, ExplicitPostTarget>;
} // namespace sscl::co
#endif // POST_TARGET_H