2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-02 20:52:21 +00:00

optimize the example for asio loop

This commit is contained in:
Vincent Lee
2014-09-15 18:14:15 +08:00
parent c161e095af
commit 61a8a8ea89

View File

@@ -31,7 +31,14 @@ inline void timer_handler( boost::asio::high_resolution_timer & timer) {
inline void run_service( boost::asio::io_service & io_service) {
boost::asio::high_resolution_timer timer( io_service, boost::chrono::seconds(0) );
timer.async_wait( boost::bind( timer_handler, boost::ref( timer) ) );
io_service.run();
while(true)
{
boost::system::error_code ec;
std::size_t num = io_service.run_one(ec);
if (num == 0)
return;
boost::this_fiber::yield();
}
}
}}}