Boost logo

Boost Users :

Subject: [Boost-users] [Asio] Combining use_future with strands
From: Sorin Fetche (sorin.fetche_at_[hidden])
Date: 2018-12-17 06:39:37


Hi,

Is there a way to combine the special use_future completion token with a
strand?
Something with the meaning of:
- the asynchronous operation should pass the result to the future it
returns, and
- the internal operations of it (if any) should run in a strand

Code snippet:
asio::io_context io_context;
asio::io_context::strand strand(io_context);
std::future<void> f = async_my_operation(io_context, <params>,
asio::use_future);
//________________________________________How to add the strand here ^^^ ?

The code area where I would like to apply this is in this test program:
https://github.com/sorf/cpp-dev-new/blob/abf9d831a0b82fb81751eee6cfa498d3b982505a/source/test/error_testing/asio_composed.cpp#L259

The self contained program and its output is here:
https://wandbox.org/permlink/pF5Hbm6jqPOmEKbO

As a background, the test program I wrote is based on these Boost.Asio
examples:
- for strand usage (i.e. bind_executor):
https://github.com/boostorg/asio/blob/develop/example/cpp03/tutorial/timer5/timer.cpp

- for composed operations:
https://github.com/boostorg/asio/blob/develop/example/cpp11/operations/composed_5.cpp

and implements a composed operation that runs multiple internal operations
in parallel and in series. Similar to the constructor of a socket or a
timer object, the operation receives as a parameter an io_context; it
doesn't offer an overload that receives a strand object directly.

The operation is then tested with callback completion, callback completion
in a strand, future and future + strand (where the test fails).

Thank you,
Sorin



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net