Nursery: Initial integration

StimulusProducer: syncAwaitAllSettlements should pump caller io_context
This commit is contained in:
2026-06-09 11:19:42 -04:00
parent 5b81ea893c
commit 91fc655b25
15 changed files with 326 additions and 383 deletions
+11 -22
View File
@@ -5,7 +5,6 @@
#include <atomic>
#include <coroutine>
#include <memory>
#include <optional>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
@@ -15,7 +14,10 @@
namespace adapters::boostAsio {
/** Coroutine awaiter: true if the delay elapsed, false if cancelled/aborted. */
/** Coroutine awaiter: true if the delay elapsed, false if cancelled/aborted.
*
* Reuses the caller-supplied deadline_timer; does not allocate a new timer.
*/
class DeadlineTimerAReq
{
public:
@@ -24,22 +26,17 @@ public:
std::atomic<bool> settled{false};
bool timerExpiredNormally = false;
std::coroutine_handle<> callerSchedHandle;
std::shared_ptr<boost::asio::deadline_timer> timer;
};
DeadlineTimerAReq(
boost::asio::io_context &resumeIoContext,
const boost::posix_time::milliseconds delay,
std::optional<std::shared_ptr<boost::asio::deadline_timer>> &timerOut)
boost::asio::deadline_timer &timer,
const boost::posix_time::milliseconds delay)
: asyncState(std::make_shared<AsyncState>()),
resumeIoContext(resumeIoContext)
{
asyncState->timer =
std::make_shared<boost::asio::deadline_timer>(resumeIoContext);
timerOut = asyncState->timer;
asyncState->timer->expires_from_now(delay);
asyncState->timer->async_wait(
timer.expires_from_now(delay);
timer.async_wait(
[this](const boost::system::error_code &error)
{
onTimer(error);
@@ -92,19 +89,11 @@ private:
};
inline auto getDeadlineTimerAReqAwaiter(
boost::asio::io_context &ioContext,
boost::asio::io_context &resumeIoContext,
boost::asio::deadline_timer &timer,
const boost::posix_time::milliseconds delay)
{
std::optional<std::shared_ptr<boost::asio::deadline_timer>> timerOut;
return DeadlineTimerAReq(ioContext, delay, timerOut);
}
inline auto getDeadlineTimerAReqAwaiter(
boost::asio::io_context &ioContext,
const boost::posix_time::milliseconds delay,
std::optional<std::shared_ptr<boost::asio::deadline_timer>> &timerOut)
{
return DeadlineTimerAReq(ioContext, delay, timerOut);
return DeadlineTimerAReq(resumeIoContext, timer, delay);
}
} // namespace adapters::boostAsio