diff --git a/Hyperbar/Mediators/Mediator.cs b/Hyperbar/Mediators/Mediator.cs index 1ae56d0..f11d20a 100644 --- a/Hyperbar/Mediators/Mediator.cs +++ b/Hyperbar/Mediators/Mediator.cs @@ -8,7 +8,7 @@ public class Mediator(IServiceProvider provider) : { private readonly ConditionalWeakTable addedHandlers = []; - public async ValueTask PublishAsync(TNotification notification, + public ValueTask PublishAsync(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification @@ -24,14 +24,12 @@ public class Mediator(IServiceProvider provider) : } } - if (handlers.Count == 0) + foreach (INotificationHandler handler in handlers) { - } - else if (handlers.Count == 1) - { - await handlers[0].Handle(notification, cancellationToken); + return handler.Handle(notification, cancellationToken); } + return default; } public ValueTask SendAsync(IRequest request,