chriskohlhoff / asio

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

Question: composed operations using deferred #1338

Open pfeatherstone opened 11 months ago

pfeatherstone commented 11 months ago

It looks like from https://think-async.com/Asio/asio-1.28.0/src/examples/cpp14/deferred/deferred_7.cpp that we can write composed operations using deferred completion token. It looks nicer than using async_compose(), co_composed<> etc. is this good practice ?

pfeatherstone commented 11 months ago

Is the associated executor propagated ?

pfeatherstone commented 11 months ago

@klemens-morgenstern

klemens-morgenstern commented 11 months ago

It is propagated and yes you can do this. I would recommend sticking to simple compositions though, this can get out of hand quickly. Also have a look a experimental::co_composed if you are using C++20

pfeatherstone commented 11 months ago

Yeah I would use async_compose() for a state machine style operation. Otherwise, deferred looks 100 times better. Very similar to what the continuable library does.

mzimbres commented 11 months ago

FYI: https://github.com/chriskohlhoff/asio/issues/1166