-
Notifications
You must be signed in to change notification settings - Fork 29
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
Async support #46
Comments
Up vote for the feature! |
Perhaps an easy entry point into the ability to run an async listener is to test if the asyncio loop is running. If it is running, await the listener. If it is not running throw an exception. This would put the responsibility of the loop on the consumer of the module. |
Best way to handle this is to try it out: create some code that exemplifies how you want to use it with co-routines, and then try to path pypubsub so it works the way you want it with those, without impacting existing functionality. Then you can submit a pull request. If some changes are needed to existing functionality, discuss it here first, before spending too much time, as there is a chance it will not be acceptable, but it also might be, or maybe there will be different approach once we discuss the reason. |
I haven't looked too deeply in what would be involved to implement this properly, but before I do I was wondering whether you have any thoughts on this.
The main thing I'd like is to be able to provide a listener callback that is a co-routine instead of a 'normal' function. My current workaround is to convert any 'await'-able calls inside my listener to sync, but I thought it might be nicer if pypubsub could handle async callbacks natively.
As a first step, it might be good enough to check if the listener is a co-routine, and convert/await it inside the relevant pypubsub-component. Might be opening up a big can of multi-thread-worms and not worth it, not sure.
Ideally of course, pypubsub would handle async stuff natively, but that is most likely too much to ask, and probably better to look at something like https://github.com/abadger/pubmarine , but overall I'm very happy with pypubsub and it fits most of my requirments perfectly.
The text was updated successfully, but these errors were encountered: