pub struct Sender { /* private fields */ }
Expand description
The handle that controls backpressure
It can be used to create tokens, changing limit and getting metrics.
See new
for more details
Implementations§
Source§impl Sender
impl Sender
Sourcepub fn token(&self) -> Token
pub fn token(&self) -> Token
Acquire a backpressure token
The token holds one unit of resource
Note: You can always acquire a token, even if capacity limit reached.
Sourcepub fn set_limit(&self, new_limit: usize)
pub fn set_limit(&self, new_limit: usize)
Change the limit for the number of connections
If limit is increased it’s applied immediately. If limit is lowered, we can’t drop connections. So listening stream is paused until there are less then new limit tokens alive (i.e. first dropped tokens may not unblock the stream).
Sourcepub fn get_active_tokens(&self) -> usize
pub fn get_active_tokens(&self) -> usize
Returns the number of currently active tokens
Can return a value larger than limit if tokens are created manually.
This can be used for metrics or debugging. You should not rely on
this value being in sync. There is also no way to wake-up when this
value is lower than limit, also see
has_capacity
.