Files
libspinscale/include/spinscale/co/postTarget.h
T
hayodea 42076d6c78 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.
2026-05-30 20:44:53 -04:00

30 lines
681 B
C++

#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