Closed per-ove closed 8 months ago
Thank you for your interest in the library. Similar issues have been raised around async support. This library is in-memory and there is no IO involved therefore it is synchronous by design. The introduction of async will nullify the performance benefits of using the library.
The fix is simple as I have explained here.
As I understand, the publish method are not fire and forget as it not return until all subscriptions are finished. I know I can fix this when invoking the publish method but it's easier to have a non blocking method in the library.
This library is meant to be in-memory, CPU bound and therefore synchronous (just like native .NET events) therefore any long running consumer should offload the work as soon as received (which is again the general pattern with .NET events).
You definitely do not want to be creating tasks like you are doing in the proposed snippet; Instead, you can wrap the MessageHub and use System.Threading.Channels
which will nicely take care of offloading your publish/subscribe.
Thank you for a good answer.
We use this a lot and are very happy with it. But there are an issue we encounter running publish from a GUI.
The publisher has no way to know many or how time consuming each action is. and sometimes this are blocking our main thread.
We have a suggestion to add a publishAsync. like the example below. What do you think?
Code snippet *****