Skip to content

Right now broadcast() sends to all clients sequentially. If one client is slow, it delays everything. #1

Description

@janwilmans

A safer version:

async def broadcast(message):
    data = json.dumps(message)

    dead = []
    tasks = []

    for ws in clients:
        tasks.append(ws.send_text(data))

    results = await asyncio.gather(*tasks, return_exceptions=True)

    for ws, result in zip(list(clients), results):
        if isinstance(result, Exception):
            dead.append(ws)

    for ws in dead:
        clients.remove(ws)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions