rippled
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
beast::test::enable_yield_to Class Reference

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

#include <yield_to.h>

Inheritance diagram for beast::test::enable_yield_to:
Inheritance graph
[legend]
Collaboration diagram for beast::test::enable_yield_to:
Collaboration graph
[legend]

Public Types

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

Public Member Functions

 enable_yield_to (std::size_t concurrency=1)
 
 ~enable_yield_to ()
 
boost::asio::io_context & get_io_context ()
 Return the io_context associated with the object.
 
template<class F0 , class... FN>
void yield_to (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 28 of file yield_to.h.

Member Typedef Documentation

◆ yield_context

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

The type of yield context passed to functions.

Definition at line 44 of file yield_to.h.

Constructor & Destructor Documentation

◆ enable_yield_to()

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

Definition at line 46 of file yield_to.h.

◆ ~enable_yield_to()

beast::test::enable_yield_to::~enable_yield_to ( )

Definition at line 54 of file yield_to.h.

Member Function Documentation

◆ get_io_context()

boost::asio::io_context & beast::test::enable_yield_to::get_io_context ( )

Return the io_context associated with the object.

Definition at line 63 of file yield_to.h.

◆ yield_to()

template<class F0 , class... FN>
void beast::test::enable_yield_to::yield_to ( 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:44
Parameters
fn...One or more functions to invoke.

Definition at line 102 of file yield_to.h.

◆ spawn() [1/2]

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

Definition at line 91 of file yield_to.h.

◆ spawn() [2/2]

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

Definition at line 112 of file yield_to.h.

Member Data Documentation

◆ ios_

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

Definition at line 31 of file yield_to.h.

◆ work_

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

Definition at line 36 of file yield_to.h.

◆ threads_

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

Definition at line 37 of file yield_to.h.

◆ m_

std::mutex beast::test::enable_yield_to::m_
private

Definition at line 38 of file yield_to.h.

◆ cv_

std::condition_variable beast::test::enable_yield_to::cv_
private

Definition at line 39 of file yield_to.h.

◆ running_

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

Definition at line 40 of file yield_to.h.