chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.97k stars 1.22k forks source link

Requesting example of integration with Boost.Fiber for post 1.70.0 #692

Open ghost opened 3 years ago

ghost commented 3 years ago

@Warchant commented on May 18, 2019, 10:36 AM UTC:

Coroutines are natively supported by asio. With coroutines it is possible to avoid callback hell, and turn async-callback-based code to look like it is synchronous. Asio has examples, and some glue code for best integration. However, native compiler coroutines require C++20 and are not available in GCC.

There is one alternative to coroutines - Boost.Fiber. This library can be used in any C++11 (or higher) project. Documentation of Boost.Fiber does not have native glue code for asio+fiber, but has nice tutorial [1] [2] and examples [3]. Though, tutorial and example code became outdated boostorg/fiber#201 post 1.70.0 release.

This issue is a request to add glue code, which will help to easily use Boost.Fiber with Boost.Asio, as well as a request to add some examples of using asio+fiber.

P.S. : I am experimenting with asio+fiber, you can check this server handler - to have clue how it works

This issue was moved by chriskohlhoff from boostorg/asio#241.

ghost commented 3 years ago

@djarek commented on May 18, 2019, 7:05 PM UTC:

I've implemented a completion token based on Boost.Context: https://github.com/djarek/ufiber/pull/7/files#diff-f542f70e89a4104c0dc28e2f83ad7f4fR242 that makes use of the features in 1.70.

I don't think that Boost.Fiber exposes the resume_with functionality of the underlying fiber, so you might not gain much by using the ASIO facilities in 1.70.