How can I debounce messages per chat room and run one async task at a time while queuing the next ones?

โš“ Rust    ๐Ÿ“… 2026-03-24    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 1      

surdeus

I have thousands of chat rooms running in an app, tokio broadcast channels

Each room needs to be able to do the following in parallel

When a message comes in, start a debounce timer, where if no messages come in before the timer ends, we call some async function on the batch of messages and await it's result

While that function is in flight, if the message loop happens again, where a message comes in, we wait for debounce, etc. we line up another async function call to be sent after the first one we sent finishes.

This is the core loop I am going for and it should just be able to keep stacking requests (I'll add a limit later) So this should happen in parallel, for each room

Alice was able to help me with denouncing but not sure how to approach the batch and in flight logicโ€ฆ MPSC?

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed