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

attempt of better integration with asio

This commit is contained in:
Oliver Kowalke
2016-01-25 21:48:18 +01:00
parent a4c2315c54
commit dd661d4e5d
4 changed files with 59 additions and 17 deletions

View File

@@ -74,6 +74,10 @@ void server( boost::asio::io_service & io_service, unsigned short port) {
}
}
void foo( std::string const& msg) {
std::cout << "foo(): " << msg << std::endl;
}
int main( int argc, char* argv[]) {
try {
if ( 2 != argc) {
@@ -85,7 +89,16 @@ int main( int argc, char* argv[]) {
boost::fibers::asio::spawn(
io_service,
boost::bind( server, boost::ref( io_service), std::atoi( argv[1]) ) );
io_service.run();
boost::fibers::fiber( foo, "abc").detach();
boost::fibers::fiber(
[](){
for ( int i = 0; i < 20; ++i) {
std::cout << "loop " << i << std::endl;
boost::this_fiber::sleep_for( std::chrono::seconds( 1) );
}
}
).detach();
boost::fibers::asio::run( io_service);
return EXIT_SUCCESS;
} catch ( std::exception const& e) {
std::cerr << "Exception: " << e.what() << "\n";