xrpld
Loading...
Searching...
No Matches
beast::test::EnableYieldTo Class Reference

Mix-in to support tests using asio coroutines. More...

#include <yield_to.h>

Inheritance diagram for beast::test::EnableYieldTo:
Collaboration diagram for beast::test::EnableYieldTo:

Public Types

using yield_context = boost::asio::yield_context
 The type of yield context passed to functions.

Public Member Functions

 EnableYieldTo (std::size_t concurrency=1)
 ~EnableYieldTo ()
boost::asio::io_context & getIoContext ()
 Return the io_context associated with the object.
template<class F0, class... FN>
void yieldTo (F0 &&f0, FN &&... fn)
 Run one or more functions, each in a coroutine.

Protected Attributes

boost::asio::io_context ios_

Private Member Functions

void spawn ()
template<class F0, class... FN>
void spawn (F0 &&f, FN &&... fn)

Private Attributes

boost::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
std::vector< std::threadthreads_
std::mutex m_
std::condition_variable cv_
std::size_t running_ = 0

Detailed Description

Mix-in to support tests using asio coroutines.

Derive from this class and use yield_to to launch test functions inside coroutines. This is handy for testing asynchronous asio code.

Definition at line 26 of file yield_to.h.

Member Typedef Documentation

◆ yield_context

using beast::test::EnableYieldTo::yield_context = boost::asio::yield_context

The type of yield context passed to functions.

Definition at line 40 of file yield_to.h.

Constructor & Destructor Documentation

◆ EnableYieldTo()

beast::test::EnableYieldTo::EnableYieldTo ( std::size_t concurrency = 1)
explicit

Definition at line 42 of file yield_to.h.

◆ ~EnableYieldTo()

beast::test::EnableYieldTo::~EnableYieldTo ( )

Definition at line 51 of file yield_to.h.

Member Function Documentation

◆ getIoContext()

boost::asio::io_context & beast::test::EnableYieldTo::getIoContext ( )

Return the io_context associated with the object.

Definition at line 60 of file yield_to.h.

◆ yieldTo()

template<class F0, class... FN>
void beast::test::EnableYieldTo::yieldTo ( F0 && f0,
FN &&... fn )

Run one or more functions, each in a coroutine.

This call will block until all coroutines terminate.

Each functions should have this signature:

void f(yield_context);
boost::asio::yield_context yield_context
The type of yield context passed to functions.
Definition yield_to.h:40
Parameters
fn...One or more functions to invoke.

Definition at line 99 of file yield_to.h.

◆ spawn() [1/2]

void beast::test::EnableYieldTo::spawn ( )
private

Definition at line 88 of file yield_to.h.

◆ spawn() [2/2]

template<class F0, class... FN>
void beast::test::EnableYieldTo::spawn ( F0 && f,
FN &&... fn )
private

Definition at line 109 of file yield_to.h.

Member Data Documentation

◆ ios_

boost::asio::io_context beast::test::EnableYieldTo::ios_
protected

Definition at line 29 of file yield_to.h.

◆ work_

boost::optional<boost::asio::executor_work_guard<boost::asio::io_context::executor_type> > beast::test::EnableYieldTo::work_
private

Definition at line 32 of file yield_to.h.

◆ threads_

std::vector<std::thread> beast::test::EnableYieldTo::threads_
private

Definition at line 33 of file yield_to.h.

◆ m_

std::mutex beast::test::EnableYieldTo::m_
private

Definition at line 34 of file yield_to.h.

◆ cv_

std::condition_variable beast::test::EnableYieldTo::cv_
private

Definition at line 35 of file yield_to.h.

◆ running_

std::size_t beast::test::EnableYieldTo::running_ = 0
private

Definition at line 36 of file yield_to.h.