Am 20.11.2016 um 12:48 schrieb Bjorn Reese:
On 11/13/2016 02:54 PM, Klemens Morgenstern wrote:
Well this will use the second pipe, though I grant you, that's not the best solution here - an error would be better. I could add an assertion, so there are no duplicates of that. On the other hand it is similar to that:
child_builder cb; cb.std_out(p); cb.std_out("output.txt");
This can be turned into a compiler error. See the sqlpp11 for inspiration.
How? How can I turn a sequence of calls valid when the object stays the same and each call is valid?
std::error_code in case something went wrong with waiting. So there's no std::error_code vs. yield_context, they do different things and it actually makes sense to use them together. Now in case you use your error_code with system, like that
bp::system("foo", ec, yield);
ec being set will indicate that the process was not launched successfully and hence the coroutine wasn't suspended.
That is not how (asio) asynchronous operations work. Errors must be reported via the handler, which in this case is the yield context. Another important requirement is that the handler is not called directly from the initiating function. See:
http://www.boost.org/doc/html/boost_asio/reference/asynchronous_operations.h...
The error_code is reported via the yield context as "yield[ec]". For yield context it may not seem like much of a difference (besides the fact that with your approach we do not yield in the error case, and therefore may starve other competing yield context) but for other async_result constructs the difference is significant.
I'm sorry, but I think you still do not understand how that works. Two things can hapen: 1. The process launches successfully --> No error in ec, the coroutine is suspended the wait-handle might fail, which is not captured (but could be with yield[ec_yield]) 2. The process does not launch --> ec is set, the couroutine is NOT suspended and nor error can occur since the code does not wait for the handle (obviously, since there is none) so yield does nothing. system(yield) does not launch, but execute asynchronously, i.e. it suspends after successful launch.