CoroutineGroup is a helper class to manage a group of coroutines. It allows to spawn multiple coroutines and wait for all of them to finish.
More...
#include <CoroutineGroup.hpp>
|
| | CoroutineGroup (boost::asio::yield_context yield, std::optional< size_t > maxChildren=std::nullopt) |
| | Construct a new Coroutine Group object.
|
| | ~CoroutineGroup () |
| | Destroy the Coroutine Group object.
|
| bool | spawn (boost::asio::yield_context yield, std::function< void(boost::asio::yield_context)> fn) |
| | Spawn a new coroutine in the group.
|
| std::optional< std::function< void()> > | registerForeign (boost::asio::yield_context yield) |
| | Register a foreign coroutine this group should wait for.
|
| void | asyncWait (boost::asio::yield_context yield) |
| | Wait for all the coroutines in the group to finish.
|
| size_t | size () const |
| | Get the number of coroutines in the group.
|
| bool | isFull () const |
| | Check if the group is full.
|
CoroutineGroup is a helper class to manage a group of coroutines. It allows to spawn multiple coroutines and wait for all of them to finish.
- Note
- This class is safe to use from multiple threads.
◆ CoroutineGroup()
| util::CoroutineGroup::CoroutineGroup |
( |
boost::asio::yield_context | yield, |
|
|
std::optional< size_t > | maxChildren = std::nullopt ) |
Construct a new Coroutine Group object.
- Parameters
-
| yield | The yield context to use for the internal timer |
| maxChildren | The maximum number of coroutines that can be spawned at the same time. If not provided, there is no limit |
◆ ~CoroutineGroup()
| util::CoroutineGroup::~CoroutineGroup |
( |
| ) |
|
◆ asyncWait()
| void util::CoroutineGroup::asyncWait |
( |
boost::asio::yield_context | yield | ) |
|
Wait for all the coroutines in the group to finish.
- Note
- This method must be called before the object is destroyed
- Parameters
-
| yield | The yield context to use for the internal timer |
◆ isFull()
| bool util::CoroutineGroup::isFull |
( |
| ) |
const |
Check if the group is full.
- Returns
- true If the group is full false otherwise
◆ registerForeign()
| std::optional< std::function< void()> > util::CoroutineGroup::registerForeign |
( |
boost::asio::yield_context | yield | ) |
|
Register a foreign coroutine this group should wait for.
- Note
- A foreign coroutine is still counted as a child one, i.e. calling this method increases the size of the group.
- Parameters
-
| yield | The yield context owning the coroutine group. |
- Returns
- A callback to call on foreign coroutine completes or std::nullopt if the group is already full.
◆ size()
| size_t util::CoroutineGroup::size |
( |
| ) |
const |
Get the number of coroutines in the group.
- Returns
- size_t The number of coroutines in the group
◆ spawn()
| bool util::CoroutineGroup::spawn |
( |
boost::asio::yield_context | yield, |
|
|
std::function< void(boost::asio::yield_context)> | fn ) |
Spawn a new coroutine in the group.
- Parameters
-
| yield | The yield context to use for the coroutine (it should be the same as the one used in the constructor) |
| fn | The function to execute |
- Returns
- true If the coroutine was spawned successfully. false if the maximum number of coroutines has been reached
The documentation for this class was generated from the following files: