autobahn-python icon indicating copy to clipboard operation
autobahn-python copied to clipboard

Documentation about async callbacks

Open faerics opened this issue 6 years ago • 0 comments

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.

faerics avatar Feb 01 '19 12:02 faerics