private ValueTask DynamicDispatchAsync <TMessage>(ConnectedClient sender, TMessage message, CancellationToken cancellationToken) { var valueTasks = _messageHandlerFactory.GetHandlersFor <TMessage>() .Select(handler => handler.HandleAsync(sender, message, cancellationToken)); return(AsyncHelpers.WhenAll(valueTasks)); }
private ValueTask DynamicDispatchAsync <TMessage>(ConnectedClient sender, TMessage message, CancellationToken cancellationToken) { var valueTasks = _messageHandlerFactory.GetHandlersFor <TMessage>() .Select(handler => handler.HandleAsync(sender, message, cancellationToken)) .ToList(); // ! Important. Without ToList handlers are being called two times. Probably due to ValueTask. return(AsyncHelpers.WhenAll(valueTasks)); }