示例#1
0
        public async ValueTask PublishAsync(TKey key, TMessage message, AsyncPublishStrategy publishStrategy, CancellationToken cancellationToken)
        {
            IAsyncMessageHandler <TMessage>?[] handlers;

            lock (gate)
            {
                if (!handlerGroup.TryGetValue(key, out var holder))
                {
                    return;
                }
                handlers = holder.GetHandlers();
            }

            if (publishStrategy == AsyncPublishStrategy.Sequential)
            {
                foreach (var item in handlers)
                {
                    if (item != null)
                    {
                        await item.HandleAsync(message, cancellationToken);
                    }
                }
            }
            else
            {
                await new AsyncHandlerWhenAll <TMessage>(handlers, message, cancellationToken);
            }
        }
示例#2
0
 public AsyncMessageBrokerCore(MessagePipeDiagnosticsInfo diagnotics, MessagePipeOptions options)
 {
     this.handlers = new FreeList <IAsyncMessageHandler <TMessage> >();
     this.defaultAsyncPublishStrategy     = options.DefaultAsyncPublishStrategy;
     this.handlingSubscribeDisposedPolicy = options.HandlingSubscribeDisposedPolicy;
     this.diagnotics = diagnotics;
 }
示例#3
0
 public AsyncMessageBrokerCore(MessagePipeDiagnosticsInfo diagnotics, MessagePipeOptions options)
 {
     this.handlerGroup = new Dictionary <TKey, HandlerHolder>();
     this.diagnotics   = diagnotics;
     this.defaultAsyncPublishStrategy     = options.DefaultAsyncPublishStrategy;
     this.handlingSubscribeDisposedPolicy = options.HandlingSubscribeDisposedPolicy;
     this.gate = new object();
 }
        public AsyncRequestAllHandler(IEnumerable <IAsyncRequestHandlerCore <TRequest, TResponse> > handlers, FilterAttachedAsyncRequestHandlerFactory handlerFactory, MessagePipeOptions options)
        {
            var collection = (handlers as ICollection <IAsyncRequestHandlerCore <TRequest, TResponse> >) ?? handlers.ToArray();

            var array = new IAsyncRequestHandlerCore <TRequest, TResponse> [collection.Count];
            var i     = 0;

            foreach (var item in collection)
            {
                array[i++] = handlerFactory.CreateAsyncRequestHandler(item);
            }

            this.handlers = array;
            this.defaultAsyncPublishStrategy = options.DefaultAsyncPublishStrategy;
        }
 public async UniTask <TResponse[]> InvokeAllAsync(TRequest request, AsyncPublishStrategy publishStrategy, CancellationToken cancellationToken)
 {
     if (publishStrategy == AsyncPublishStrategy.Sequential)
     {
         var responses = new TResponse[handlers.Length];
         for (int i = 0; i < handlers.Length; i++)
         {
             responses[i] = await handlers[i].InvokeAsync(request, cancellationToken);
         }
         return(responses);
     }
     else
     {
         return(await new AsyncRequestHandlerWhenAll <TRequest, TResponse>(handlers, request, cancellationToken));
     }
 }
示例#6
0
        public async ValueTask PublishAsync(TMessage message, AsyncPublishStrategy publishStrategy, CancellationToken cancellationToken)
        {
            var array = handlers.GetValues();

            if (publishStrategy == AsyncPublishStrategy.Sequential)
            {
                foreach (var item in array)
                {
                    if (item != null)
                    {
                        await item.HandleAsync(message, cancellationToken);
                    }
                }
            }
            else
            {
                await new AsyncHandlerWhenAll <TMessage>(array, message, cancellationToken);
            }
        }
示例#7
0
 public ValueTask PublishAsync(TKey key, TMessage message, AsyncPublishStrategy publishStrategy, CancellationToken cancellationToken)
 {
     return(core.PublishAsync(key, message, publishStrategy, cancellationToken));
 }
示例#8
0
 public ValueTask PublishAsync(TMessage message, AsyncPublishStrategy publishStrategy, CancellationToken cancellationToken)
 {
     lastMessage = message;
     return(core.PublishAsync(message, publishStrategy, cancellationToken));
 }
示例#9
0
 public UniTask PublishAsync(TMessage message, AsyncPublishStrategy publishStrategy, CancellationToken cancellationToken)
 {
     return(core.PublishAsync(message, publishStrategy, cancellationToken));
 }
示例#10
0
 public ValueTask PublishAsync(TMessage message, AsyncPublishStrategy publishStrategy, CancellationToken cancellationToken)
 {
     return(broker.PublishAsync(message, publishStrategy, cancellationToken));
 }