Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nice-to-have: websocket receiver task should be returned/exposed by API to allow exception handling #64

Open
svennystrom opened this issue Oct 4, 2022 · 2 comments

Comments

@svennystrom
Copy link

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()

@svennystrom
Copy link
Author

And a big Thank You for publishing your work here!

@00prometheus
Copy link

I found a work-around for this, but it isn't pretty: #86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants