diff --git a/docs/howto/patterns.rst b/docs/howto/patterns.rst index e0602b6f..e97755e5 100644 --- a/docs/howto/patterns.rst +++ b/docs/howto/patterns.rst @@ -38,12 +38,12 @@ To send messages to the WebSocket connection:: from websockets.exceptions import ConnectionClosed async def producer_handler(websocket): - try: - while True: + while True: + try: message = await produce() await websocket.send(message) - except ConnectionClosed: - break + except ConnectionClosed: + break In this example, ``produce()`` is a coroutine implementing your business logic for generating the next message to send on the WebSocket connection.