public Task <T> InvokeAsync <T>(Func <IModel, T> channelAction)
        {
            Preconditions.CheckNotNull(channelAction, "channelAction");

            var tcs = new TaskCompletionSource <T>();

            try
            {
                queue.Add(() =>
                {
                    if (cancellation.IsCancellationRequested)
                    {
                        tcs.TrySetCanceledSafe();
                        return;
                    }
                    try
                    {
                        persistentChannel.InvokeChannelAction(channel => tcs.TrySetResultSafe(channelAction(channel)));
                    }
                    catch (Exception e)
                    {
                        tcs.TrySetExceptionSafe(e);
                    }
                }, cancellation.Token);
            }
            catch (OperationCanceledException)
            {
                tcs.TrySetCanceled();
            }
            return(tcs.Task);
        }
Example #2
0
        public Task <T> InvokeAsync <T>(Func <IModel, T> channelAction)
        {
            Preconditions.CheckNotNull(channelAction, "channelAction");

            var tcs = new TaskCompletionSource <T>();
            // Set the start time used for calculating the message timeout to be the time when it was added to the queue,
            // instead of the time when it is pulled out of the queue when the includeQueTimeInTimeout option is used in the connection string.
            DateTime startTime = DateTime.UtcNow;

            try
            {
                queue.Add(() =>
                {
                    if (cancellation.IsCancellationRequested)
                    {
                        tcs.TrySetCanceledSafe();
                        return;
                    }
                    try
                    {
                        persistentChannel.InvokeChannelAction(channel => tcs.TrySetResultSafe(channelAction(channel)), startTime);
                    }
                    catch (Exception e)
                    {
                        tcs.TrySetExceptionSafe(e);
                    }
                }, cancellation.Token);
            }
            catch (OperationCanceledException)
            {
                tcs.TrySetCanceled();
            }
            return(tcs.Task);
        }
Example #3
0
 private static void Confirm(TaskCompletionSource <object> tcs, ulong deliveryTag, bool isNack)
 {
     if (isNack)
     {
         tcs.TrySetExceptionSafe(new PublishNackedException(string.Format("Broker has signalled that publish {0} was unsuccessful", deliveryTag)));
     }
     else
     {
         tcs.TrySetResultSafe(null);
     }
 }
 private static void Confirm(TaskCompletionSource<object> tcs, ulong deliveryTag, bool isNack)
 {
     if (isNack)
     {
         tcs.TrySetExceptionSafe(new PublishNackedException(string.Format("Broker has signalled that publish {0} was unsuccessful", deliveryTag)));
     }
     else
     {
         tcs.TrySetResultSafe(null);
     }
 }