Boost logo

Boost :

From: Klemens Morgenstern (klemensdavidmorgenstern_at_[hidden])
Date: 2023-07-25 05:31:36


So I just checked the faux-routine and it's possible, but pretty pointless
(just brings overhead for a bit of syntactic sugar).

You can use `co_await asio::spawn(exec, stackful_coro, async::use_op)` into
the asio stackful coros and then `async::spawn(exec, async_coro,
yield_context)` to go the other way.
I think the asio completion-token API is perfect for this and also works
fine with asio::awaitable.

On Tue, Jul 25, 2023 at 1:09 PM Klemens Morgenstern <
klemensdavidmorgenstern_at_[hidden]> wrote:

> Do you mean asio::spawn with async? "co_await asio::spawn(co_await
> async::this_coro::executor, my_stackful_coro, async::use_op)" would do. It
> can handle any async operation, of which asio::spawn is one.
>
> There is no integration between boost.context and async (and there can't
> be, I think). I wonder if there could be a faux-routine,
> that looks like a async-coro, but is actually a boost.context primitive
> underneath.
>
>
>
> Boost.async integrates with everything asio, through the use_op completion
> token, so you can just use it with boost.process (v2 would be recommended)
> like this:
>
> That could look akin to this:
>
> promise<void> pipe_reader(asio::readable_pipe & pr)
> {
> std::string buffer;
> buffer.resize(4096);
> std::size_t n = co_await pr.async_read_some(asio::buffer(buffer),
> async::use_op);
> // do something with the data
> pr.close();
> }
>
> namespace vs = boost::process::v2;
> asio::readable_pipe rp{co_await async::this_coro::executor};
> v2::process proc(co_await async::this_coro::executor, "/usr/bin/cat",
> {"source.txt"}, bind_stdio{.stdout=rp});
> co_await async::join(pipe_reader(rp), proc.async_wait(async::use_op));
>
>
> On Tue, Jul 25, 2023 at 12:22 PM oliver.kowalke--- via Boost <
> boost_at_[hidden]> wrote:
>
>> Because my code relies heavily on asio's spawn() could you provide
>> examples using spawn() in the git repo?
>>
>> How does boost.async integrate boost.process? I'm especially interested
>> in adync. reading/writing from/to forked process' stdin/stout/stderr.
>>
>> Oliver
>>
>> 24.07.2023 18:59:47 Niall Douglas via Boost <boost_at_[hidden]>:
>>
>> > On 24/07/2023 15:51, Phil Endecott via Boost wrote:
>> >> Klemens Morgenstern wrote:
>> >>> I am seeking endorsement for my C++20 async coroutine library
>> >>> boost.async.
>> >>
>> >>> - coroutine types (eager, lazy, generators)
>> >>
>> >> Can the generators be used without ASIO? Are they compatible
>> >> the the C++23 std::generator?
>> >
>> > His library works without effort with all third party awaitables. This
>> > is a very big thing, previously using C++ coroutines with ASIO meant you
>> > had to use ASIO's awaitables and couldn't use any others. With this
>> > library, you can mix and match any type of awaitable freely with ASIO
>> > code. That's an enormous leap forward in C++ coroutine usability.
>> >
>> > I'll be review managing it we currently think between the 8th and 18th
>> > of August.
>> >
>> > Niall
>> >
>> > _______________________________________________
>> > Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost
>>
>> _______________________________________________
>> Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost
>>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk