Boost logo

Boost :

From: Vinícius dos Santos Oliveira (vini.ipsmaker_at_[hidden])
Date: 2019-08-10 02:27:25


Em sex, 9 de ago de 2019 às 16:12, Jared McIntyre via Boost <
boost_at_[hidden]> escreveu:

> What I need is a way for each call to bottleneck() to
> fully complete before the next one starts, and each call occurs in the
> order they were called. This would make the output 3 2 1 0. I also want to
> allow other asynchronous routines on the io_service to run when the
> coroutine is yielding (so no cheating and turning the delay timer into a
> sleep).
>

Take a look at this project: https://github.com/blinktrade/iofiber

It should solve your needs.

You could... like:

spawn(ioservice, [](fiber::this_fiber this_fiber) {
    spawn(this_fiber, std::bind(&bottleneck, 3s, _1))
        .join(this_fiber);
    spawn(this_fiber, std::bind(&bottleneck, 2s, _1))
        .join(this_fiber);
    spawn(this_fiber, std::bind(&bottleneck, 1s, _1))
        .join(this_fiber);
    spawn(this_fiber, std::bind(&bottleneck, 0s, _1))
        .join(this_fiber);
})
.detach();

With IOFiber, spawn() returns a fiber handle that you can use to join() the
fiber. The handle is moveable and then you can pass it around. Check the
documentation.

-- 
Vinícius dos Santos Oliveira
https://vinipsmaker.github.io/

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