autobahn-python
autobahn-python copied to clipboard
Documentation about async callbacks
While facing with #1104, I realised that the callbacks in the websocket protocol may be coroutines. So, instead of
class Protocol(WebSocketServerProtocol):
def onOpen(self):
asyncio.ensure_future(coro(), loop=loop)
one could write
class Protocol(WebSocketServerProtocol):
async def onOpen(self):
await coro
The difference is there's no way to specify a loop, but the opportunity to use coroutines is very important yet undocumented.