pub struct Throttler<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>>,
pub actor_id: Ustr,
/* 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.
actor_id: Ustr
The actor ID of the throttler.
Implementations§
Source§impl<T, F> Throttler<T, F>
impl<T, F> Throttler<T, F>
pub fn new( limit: usize, interval: u64, clock: Rc<RefCell<dyn Clock>>, timer_name: String, output_send: F, output_drop: Option<F>, actor_id: Ustr, ) -> Self
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:
- to process buffered messages
- 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 Throttler<T, F>where
F: Freeze,
impl<T, F> !RefUnwindSafe for Throttler<T, F>
impl<T, F> !Send for Throttler<T, F>
impl<T, F> !Sync for Throttler<T, F>
impl<T, F> Unpin for Throttler<T, F>
impl<T, F> !UnwindSafe for Throttler<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