INNER CODE UNIT · Python

_send_websocket_payload

ok-oldking/ok-script · ok/ui/web/app.py:111

async def _send_websocket_payload(websocket, payload):
    """Send an event, treating Starlette's post-close race as disconnect."""
    try:
        await websocket.send_json(payload)
    except RuntimeError as error:
        message = str(error)
        if ("Unexpected ASGI message 'websocket.send'" in message
                and "after sending 'websocket.close'" in message):
            return False
        raise
    return True


async def _wait_for_websocket_disconnect(websocket):
    """Consume inbound frames so ASGI can deliver an idle client's disconnect."""
    while True:
        message = await websocket.receive()
        if message.get("type") == "websocket.disconnect":

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…