Struct MessageDebouncer
pub struct MessageDebouncer { /* private fields */ }Expand description
Accumulates rapid inbound messages per sender and fires a single combined message after the debounce window elapses without new input.
Implementations§
Source§impl MessageDebouncer
impl MessageDebouncer
Sourcepub fn new(window: Duration) -> Self
pub fn new(window: Duration) -> Self
Create a new debouncer with the given window. A zero duration disables debouncing (all messages pass through).
Sourcepub async fn debounce(&self, sender_key: &str, message: &str) -> DebounceResult
pub async fn debounce(&self, sender_key: &str, message: &str) -> DebounceResult
Submit a message for debouncing using the debouncer’s default window.
- If the window is zero, returns
DebounceResult::Passthroughimmediately. - Otherwise, accumulates the message under
sender_keyand returnsDebounceResult::Pendingwith a receiver that will eventually yield the concatenated messages once the window expires.
Each new message resets the timer. When the timer fires it concatenates all
accumulated messages with "\n" and sends them through the oneshot channel.
Sourcepub async fn debounce_with_window(
&self,
sender_key: &str,
message: &str,
window: Duration,
) -> DebounceResult
pub async fn debounce_with_window( &self, sender_key: &str, message: &str, window: Duration, ) -> DebounceResult
Submit a message for debouncing with an explicit per-call window.
Behaves identically to debounce but uses the provided
window instead of the debouncer’s default. This is used by channels that
override the global debounce window (e.g., per-alias Telegram config).
Sourcepub async fn cancel(&self, sender_key: &str) -> bool
pub async fn cancel(&self, sender_key: &str) -> bool
Cancel and remove an open accumulation bucket.
Dropping the bucket’s result sender wakes its receiver with an error, so callers can retire any position reserved for the cancelled turn. The next message for the same key always opens a fresh bucket.