If there is a network issue an exception is thrown by the websocket library; for code consuming the API it would be convenient to get the task created by AvanzaSocket::init() to receive the socket data - making it possible to wait for and handle possible exceptions together with other tasks (using for example asyncio.gather()), as well as being able to cancel it for a controlled shutdown. Since the init() method does not return the result of asyncio.ensure_future(self.__create_socket()) this requires some extra fiddling in the consuming code, making it sensitive to changes in the API.
async def init(self):
asyncio.ensure_future(self.__create_socket()) # nice if the result of this could be returned at the end of the method
await self.__wait_for_websocket_to_be_connected()
Ideally the actual call to AvanzaSocket::init() should also be wrapped by the Avanza class allowing access without having to go through the _socket member, as - say - Avanza::init_socket() --> return await self._socket.init()
If there is a network issue an exception is thrown by the websocket library; for code consuming the API it would be convenient to get the task created by AvanzaSocket::init() to receive the socket data - making it possible to wait for and handle possible exceptions together with other tasks (using for example asyncio.gather()), as well as being able to cancel it for a controlled shutdown. Since the init() method does not return the result of asyncio.ensure_future(self.__create_socket()) this requires some extra fiddling in the consuming code, making it sensitive to changes in the API.
Ideally the actual call to AvanzaSocket::init() should also be wrapped by the Avanza class allowing access without having to go through the _socket member, as - say - Avanza::init_socket() --> return await self._socket.init()