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

Switch to ValueTask<T> and refactor Notify > NotifyAsync #125

Open
kzu opened this issue Nov 8, 2024 · 0 comments
Open

Switch to ValueTask<T> and refactor Notify > NotifyAsync #125

kzu opened this issue Nov 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@kzu
Copy link
Member

kzu commented Nov 8, 2024

There are a number of minor drawbacks to the current IMessageBus interface:

  1. ExecuteAsync forces an allocation even when commands complete synchronously (see https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/)
  2. Notify cannot involve async behavior (i.e. persisting events to a queue or cloud)

For that reason, we'd like to make the following changes:

ValueTask ExecuteAsync(...)
ValueTask<TResult> ExecuteAsync<TResult>(...)
ValueTask NotifyAsync<TEvent>(...)

Except for the last, the other two should be mostly source-compatible if the consumers are simply awaiting the result.

For legacy code using Notify synchronously, an extension method could run NotifyAsync and spinwait on IsCompleted, say.

Back this issue
Back this issue

@kzu kzu added the enhancement New feature or request label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant