pub struct InnerThrottler<T, F> {
pub recv_count: usize,
pub sent_count: usize,
pub is_limiting: bool,
pub limit: usize,
pub buffer: VecDeque<T>,
pub timestamps: VecDeque<UnixNanos>,
pub clock: Rc<RefCell<dyn Clock>>,
/* private fields */
}
Expand description
Throttler rate limits messages by dropping or buffering them.
Throttler takes messages of type T and callback of type F for dropping or processing messages.
Fields§
§recv_count: usize
The number of messages received.
sent_count: usize
The number of messages sent.
is_limiting: bool
Whether the throttler is currently limiting the message rate.
limit: usize
The maximum number of messages that can be sent within the interval.
buffer: VecDeque<T>
The buffer of messages to be sent.
timestamps: VecDeque<UnixNanos>
The timestamps of the sent messages.
clock: Rc<RefCell<dyn Clock>>
The clock used to keep track of time.
Implementations§
Source§impl<T, F> InnerThrottler<T, F>
impl<T, F> InnerThrottler<T, F>
Sourcepub fn new(
limit: usize,
interval: u64,
clock: Rc<RefCell<dyn Clock>>,
timer_name: String,
output_send: F,
output_drop: Option<F>,
) -> Self
pub fn new( limit: usize, interval: u64, clock: Rc<RefCell<dyn Clock>>, timer_name: String, output_send: F, output_drop: Option<F>, ) -> Self
Creates a new InnerThrottler
instance.
Sourcepub fn set_timer(&mut self, callback: Option<TimeEventCallback>)
pub fn set_timer(&mut self, callback: Option<TimeEventCallback>)
Set timer with a callback to be triggered on next interval.
Typically used to register callbacks:
super::callbacks::ThrottlerProcess
to process buffered messagessuper::callbacks::ThrottlerResume
to stop buffering
Sourcepub fn delta_next(&mut self) -> u64
pub fn delta_next(&mut self) -> u64
Time delta when the next message can be sent.
Trait Implementations§
Auto Trait Implementations§
impl<T, F> Freeze for InnerThrottler<T, F>where
F: Freeze,
impl<T, F> !RefUnwindSafe for InnerThrottler<T, F>
impl<T, F> !Send for InnerThrottler<T, F>
impl<T, F> !Sync for InnerThrottler<T, F>
impl<T, F> Unpin for InnerThrottler<T, F>
impl<T, F> !UnwindSafe for InnerThrottler<T, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more