An adaptor to throttle access to a channel. More...
#include <channel.hpp>
Public Member Functions | |
| ThrottlingAdaptor (std::shared_ptr< Channel > channel, std::ptrdiff_t max_tickets) | |
| Create an adaptor that throttles sends into a channel. More... | |
| coro::task< Ticket > | acquire () |
| Obtain a ticket to send a message. More... | |
An adaptor to throttle access to a channel.
This adds a semaphore-based throttle to a channel to cap the number of suspended coroutines that can be waiting to send into it. It is useful when writing producer nodes that otherwise do not depend on an input channel.
Definition at line 103 of file channel.hpp.
|
inlineexplicit |
Create an adaptor that throttles sends into a channel.
| channel | Channel to throttle. |
| max_tickets | Maximum number of simultaneous tickets for sending into the channel. |
This adaptor is typically used for producer tasks that have no dependencies but where we nonetheless want to introduce a suspension point before sending into an output channel. Such a task can accept the output channel and wrap it in a ThrottlingAdaptor. Consumers of the adapted channel must first acquire a ticket to send before they can send. At most max_tickets consumers can pass the acquire suspension point at once.
Example usage:
Definition at line 216 of file channel.hpp.
|
inline |
Obtain a ticket to send a message.
Suspends if all tickets are currently handed out.
| std::runtime_error | If the semaphore is shut down. |
Ticket that grants permission to send a message. Definition at line 235 of file channel.hpp.