2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-01-29 19:42:08 +00:00
Files
fiber/examples/asio/loop.hpp
Nat Goodspeed 99db8d50a8 Add section about integration with another main loop.
Asio integration may be a much larger topic, per email.
2015-08-19 06:18:08 -04:00

44 lines
1.1 KiB
C++

// Copyright Eugene Yakubovich 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <chrono>
#include <boost/asio.hpp>
#include <boost/asio/high_resolution_timer.hpp>
#include <boost/config.hpp>
#include <boost/fiber/all.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace fibers {
namespace asio {
//[timer_handler
inline void timer_handler( boost::asio::high_resolution_timer & timer) {
boost::this_fiber::yield();
timer.expires_from_now( boost::fibers::wait_interval() );
timer.async_wait( std::bind( timer_handler, std::ref( timer) ) );
}
//]
//[run_service
inline void run_service( boost::asio::io_service & io_service) {
boost::asio::high_resolution_timer timer( io_service, std::chrono::seconds(0) );
timer.async_wait( std::bind( timer_handler, std::ref( timer) ) );
io_service.run();
}
//]
}}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif