cirospaciari / socketify.py

Bringing Http/Https and WebSockets High Performance servers for PyPy3 and Python3
https://www.socketify.dev
MIT License
1.39k stars 50 forks source link

Clarify how to handle web socket back pressure #159

Closed domoritz closed 8 months ago

domoritz commented 8 months ago

The docs should be clearer about how to handle back pressure. Right now, the explanation is

def ws_message(ws, message, opcode):
    #Ok is false if backpressure was built up, wait for drain
    ok = ws.send(message, opcode)

But how should I wait for drain? Should I busy wait before returning from the call or wait in the next call or something else?

cirospaciari commented 8 months ago

You should queue this in some way and use the ws_drain handler to try send it again