chriskohlhoff / asio

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

Question: composed operations using deferred #1338

Open pfeatherstone opened 1 year ago

pfeatherstone commented 1 year 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 1 year ago

Is the associated executor propagated ?

pfeatherstone commented 1 year ago

@klemens-morgenstern

klemens-morgenstern commented 1 year 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 1 year 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 1 year ago

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