websocket_batch_handler

Function websocket_batch_handler 

Source
pub fn websocket_batch_handler<F, Fut, R>(
    f: F,
    batch_size: usize,
    timeout_ms: u64,
) -> BatchMessageHandler<F>
where F: Fn(WebSocketConnection, Vec<Message>) -> Fut + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse,
Available on crate feature websocket only.
Expand description

Create a batch message handler with specified batch size and timeout.

§Parameters

  • f - Function that processes a batch of messages
  • batch_size - Maximum messages per batch before flushing
  • timeout_ms - Maximum milliseconds to wait before flushing partial batch

§Example

let handler = websocket_batch_handler(
    |ws, messages| async move {
        // Process up to 50 messages at once
        for msg in messages {
            // Handle message...
        }
        Response::ok()
    },
    50,      // Batch size
    100      // Timeout in milliseconds
);