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

Sending a message from a handler #16

Open
mludvig opened this issue Apr 8, 2021 · 1 comment
Open

Sending a message from a handler #16

mludvig opened this issue Apr 8, 2021 · 1 comment

Comments

@mludvig
Copy link

mludvig commented Apr 8, 2021

I'm trying to use MessageBus in multi-threaded program where one thread (e.g. Button) sends a ButtonMessage() to the bus. Then I've got a Controller thread that's subscribed to the ButtonMessage() messages and receives it. In the Controller.handler() it decides what to do with it and then sends another message, e.g. DisplayMessage() with some payload back to the messagebus which should be handled by the Display thread. At that point all the hell breaks loose, the Controller.handler() starts to get called recursively, the DisplayMessage() is never delivered and in the end it all crashes.

As a workaround I have to listen for the ButtonMessage() in Display which feels like an anti-pattern, the Display shouldn't care where the event comes from or the Button shouldn't need to know what kind of DisplayMessage() to send. It should all be glued together only in the Controller.

It'd be great if:

  • we could send messages in a fire and forget mode - most of the time my senders don't care about the return values, especially not from other threads.
  • we could send new messages from message handlers - my Controller would then be the only thing that needs to know about all the other components and the messages they expect but the individual components won't have to have a clue.

Are there any plans to do that?

@omars44
Copy link

omars44 commented Oct 4, 2023

@mludvig normally, this is done through constructor injection of the bus
A good library that does decent DI in python is "injector"

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