pause


Pause the execution of the current coroutine until it is manually resumed. Useful for deferring for an unspecified or unknown amount of time. For example, waiting for the user to do something.


Example
async_function
your_class::do_pause() noexcept
{
    pause_pack return_pp = co_await pause(
        []
        (pause_pack* _pp) noexcept
            {
                /* resume the coroutine in thread 1*/
                _pp->thread_ = thread_t{1};
                /* Set the data to 42 */
                _pp->data_ = 42;
                /* wait 10 seconds and resume */
                unpause(_pp, order::now() + order::seconds(10));
            }
        );

    /* now executing in thread 1 */
    assert(return_pp.data_ == 42);
    assert(return_pp.thread_.thread_ == 1);
}

A pause_pack has a non-owning reference to the coroutines state and also provides two options to set for resumption: The data to return and the thread to resume in.

struct zab::pause_pack

Data pack for pausing coroutines.

Public Members

thread_t thread_ = thread_t{}

The thread to resume the coroutine in.

std::intptr_t data_ = 0

Any data that you wish to pass to the coroutine.

tagged_event handle_

The coroutine to resume.


pause(...) will give the Functor a non-owner ptr to the pause_pack. This ptr is valid until unpause has been called with it.

//TODO: fix doxygen generation of functions with concepts…

template<details::NoThrowInvoacablePP Functor>
inline auto zab::pause(Functor &&_func) noexcept

Suspend a coroutine until unpause is called.

Template Parameters

Functor – callable type.

Parameters

_func – The callable that is given the pause_pack* for resumption. @co_return std::intptr_t The value of pause_pack->data_ given to the Functor.


After the coroutine has been paused thread_ and data_ can be set to the desired state and then the coroutine can be resumed using unpause(...). This resumption is thread-safe so may be called in any thread, but the coroutine will be resumed in the thread specified by thread_.

void zab::unpause(engine *_engine, pause_pack &_pause, order_t _order) noexcept

Continues a paused corountine.

Parameters
  • _pause – The pause pack to resume.

  • _order[in] The ordering to apply.

void zab::unpause(engine *_engine, pause_pack &_pause) noexcept

Continues a paused corountine.

Parameters

_pause – The pause pack to resume.