Send messages as a batch. Single messages are sent as-is. Multiple messages are wrapped in a JSON array without re-parsing - just string concatenation. Args: send_text: Async function to send text data over WebSocket messages: List of pre-serialized JSON message strings
(send_text: Callable[[str], Any], messages: list)
| 300 | |
| 301 | |
| 302 | async def _send_batched(send_text: Callable[[str], Any], messages: list) -> bool: |
| 303 | """Send messages as a batch. |
| 304 | |
| 305 | Single messages are sent as-is. Multiple messages are wrapped |
| 306 | in a JSON array without re-parsing - just string concatenation. |
| 307 | |
| 308 | Args: |
| 309 | send_text: Async function to send text data over WebSocket |
| 310 | messages: List of pre-serialized JSON message strings |
| 311 | |
| 312 | Returns: |
| 313 | True if send succeeded, False if connection was closed |
| 314 | """ |
| 315 | try: |
| 316 | if len(messages) == 1: |
| 317 | await send_text(messages[0]) |
| 318 | else: |
| 319 | # Wrap in array: "[msg1,msg2,msg3]" |
| 320 | await send_text("[" + ",".join(messages) + "]") |
| 321 | return True |
| 322 | except Exception: # pylint: disable=broad-exception-caught |
| 323 | return False # WebSocketDisconnect, RuntimeError, etc. |
| 324 | |
| 325 | |
| 326 | def make_callback_done_handler( |
no outgoing calls
no test coverage detected
searching dependent graphs…