/// <inheritdoc />
        public Task <T> InvokeAsync <T>(
            Func <IModel, T> channelAction, ChannelDispatchOptions channelOptions, CancellationToken cancellationToken
            )
        {
            Preconditions.CheckNotNull(channelAction, "channelAction");

            // TODO createChannelFactory could be called multiple time, fix it
            var channel = channelPerOptions.GetOrAdd(channelOptions, createChannelFactory);

            return(channel.InvokeChannelActionAsync(channelAction, cancellationToken));
        }
示例#2
0
 public static Task InvokeAsync(
     this IClientCommandDispatcher dispatcher,
     Action <IModel> channelAction,
     ChannelDispatchOptions channelOptions,
     CancellationToken cancellationToken
     )
 {
     return(dispatcher.InvokeAsync <NoContentStruct>(model =>
     {
         channelAction(model);
         return default;
     }, channelOptions, cancellationToken));
 }
        /// <inheritdoc />
        public async Task <T> InvokeAsync <T>(
            Func <IModel, T> channelAction, ChannelDispatchOptions options, CancellationToken cancellationToken
            )
        {
            Preconditions.CheckNotNull(channelAction, "channelAction");

            // TODO channelsPoolFactory could be called multiple time, fix it
            var channelsPool = channelsPoolPerOptions.GetOrAdd(options, channelsPoolFactory);
            var channel      = await channelsPool.DequeueAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                return(await channel.InvokeChannelActionAsync(channelAction, cancellationToken).ConfigureAwait(false));
            }
            finally
            {
                channelsPool.Enqueue(channel);
            }
        }