示例#1
0
        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));
        }
示例#2
0
    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));
    }