Am 13.08.24 um 16:49 schrieb Thomas Fowlery via Boost:
On Tue, Aug 13, 2024 at 3:32 PM olk via Boost
wrote: You could use boost::asio::spawn() (utilizes stackful coroutines).
Hmm, thanks. My concern with this is having to pass the boost::asio::yield_context parameter everywhere. I suppose I could use a thread_local to pass the parameter implicitly somehow, although I'm not sure how to do it safely in this context.
Its simple: |int main () {||||boost::asio::io_service io_service;||boost::asio::spawn( io_service, [io_service](||boost::asio::yield_context yc)||{ for (;;) { ||boost::asio::deadline_timer timer(io_service); timer.expires_from_now(boost::posix_time::seconds(1)); std::cout << "do wait" << std::endl; timer.async_wait(yc); std::cout << "woken up" << std::endl; | |} }); io_service.run(); } |