Background
I am using actix and actix-web-actors to implement a websocket application. In server, a session will respond to message A sent from manager to send text to client. So I have the following code:
impl Handler<A> for Session {
type Result = ();
fn handle(&mut self, msg: A, ctx: &mut ws::WebsocketContext<Self>) {
ctx.text(/* some text */)
}
}
However, manager may send a lot of message A in a short time, so it is wise to "debounce" (if I pick the right word) inside this handler to minimize net communication, i.e., if there are multiple message A sent within a certain time (let's say 1 second), only the last message will be sent (and each new message will update the timer to re-count the time).
Question
I think inside async environment, it may be easier to implement such functionality (but I can't find any popular libraries in crates.io which provide such functionality). But actix's message handler is in a sync environment, which may be harder to "debounce".
I wonder whether it is necessary to use multi-thread to implement this feature, which is very heavy-weight and make a simple thing much more complicated, or there is a simple way or crate I can use to handle this thing?