konradhalas / buslane

Simple message (event/command) bus.
MIT License
31 stars 2 forks source link

Support async/await #1

Open JosXa opened 4 years ago

JosXa commented 4 years ago

Hey there, awesome project - loving it so far. I have a bunch of projects where I use asyncio and I was wondering if that's going to come to the library in the future. If you give me the Go, maybe I can make a PR for it, but it would be nice to hear your thoughts on architecture for that :)

0mars commented 4 years ago

I like the idea too, and I'm using this package for a decent microserviced app. I would love to see this lib grow! <3

JosXa commented 4 years ago

For the time being, this does a decent job as a hack (assuming the execution order of your commands and events doesn't matter):

    def handle(self, event: Event, handler: EventHandler) -> None:
        self.log.info(f"Handling event {event} by {handler}")
        res = handler.handle(event)
        if inspect.isawaitable(res):
            asyncio.ensure_future(res)
konradhalas commented 4 years ago

Hi @JosXa thank you very much for reporting this issue.

TBH I abandoned this project because I didn't know that somebody expect me is using it ;) But as I can see it has at least 3 users so of course it's worth to maintain it.

Async support sounds like a very good idea. As far as I remember I wanted to add some kind of "plugins architecture" to support different types of backends (threads, processes, Celery, etc). It looks that async could somehow intersect with this idea, but TBH I don't remember how I want to solve this problem.

So I would say that I'm open for discussions and PR's. I will try to find my first approach to "plugins architecture" - I believe that I have some local branch with these changes but I also remember that I didn't like it ;)

0mars commented 4 years ago

@konradhalas I'm very happy to hear that, keep up the great work!

Good architecture btw!! I like the plugin approach if you need help developing ideas or maintaining it let me know, would be happy to help!