Ejemplo n.º 1
0
        internal Task <T> WriteDirectAsync <T>(Message message, ResultProcessor <T> processor, object asyncState = null, PhysicalBridge bridge = null)
        {
            var source = TaskResultBox <T> .Create(out var tcs, asyncState);

            message.SetSource(processor, source);
            if (bridge == null)
            {
                bridge = GetBridge(message.Command);
            }

            WriteResult result;

            if (bridge == null)
            {
                result = WriteResult.NoConnectionAvailable;
            }
            else
            {
                var write = bridge.TryWriteAsync(message, isSlave);
                if (!write.IsCompletedSuccessfully)
                {
                    return(WriteDirectAsync_Awaited <T>(this, message, write, tcs));
                }
                result = write.Result;
            }

            if (result != WriteResult.Success)
            {
                var ex = Multiplexer.GetException(result, message, this);
                ConnectionMultiplexer.ThrowFailed(tcs, ex);
            }
            return(tcs.Task);
        }
Ejemplo n.º 2
0
        private static async Task <T> WriteDirectAsync_Awaited <T>(ServerEndPoint @this, Message message, ValueTask <WriteResult> write, TaskCompletionSource <T> tcs)
        {
            var result = await write.ForAwait();

            if (result != WriteResult.Success)
            {
                var ex = @this.Multiplexer.GetException(result, message, @this);
                ConnectionMultiplexer.ThrowFailed(tcs, ex);
            }
            return(await tcs.Task.ForAwait());
        }
Ejemplo n.º 3
0
        internal Task <T> QueueDirectAsync <T>(Message message, ResultProcessor <T> processor, object asyncState = null, PhysicalBridge bridge = null)
        {
            var tcs    = TaskSource.CreateDenyExecSync <T>(asyncState);
            var source = ResultBox <T> .Get(tcs);

            message.SetSource(processor, source);
            if (!(bridge ?? GetBridge(message.Command)).TryEnqueue(message, isSlave))
            {
                ConnectionMultiplexer.ThrowFailed(tcs, ExceptionFactory.NoConnectionAvailable(multiplexer.IncludeDetailInExceptions, message.Command, message, this));
            }
            return(tcs.Task);
        }
Ejemplo n.º 4
0
        internal Task <T> QueueDirectAsync <T>(Message message, ResultProcessor <T> processor, object asyncState = null, PhysicalBridge bridge = null)
        {
            var tcs    = TaskSource.Create <T>(asyncState);
            var source = ResultBox <T> .Get(tcs);

            message.SetSource(processor, source);
            if (bridge == null)
            {
                bridge = GetBridge(message.Command);
            }
            if (!bridge.TryEnqueue(message, isSlave))
            {
                ConnectionMultiplexer.ThrowFailed(tcs, ExceptionFactory.NoConnectionAvailable(Multiplexer.IncludeDetailInExceptions, Multiplexer.IncludePerformanceCountersInExceptions, message.Command, message, this, Multiplexer.GetServerSnapshot()));
            }
            return(tcs.Task);
        }
        internal Task <T> WriteDirectAsync <T>(Message message, ResultProcessor <T> processor, object asyncState = null, PhysicalBridge bridge = null)
        {
            var tcs    = TaskSource.Create <T>(asyncState);
            var source = ResultBox <T> .Get(tcs);

            message.SetSource(processor, source);
            if (bridge == null)
            {
                bridge = GetBridge(message.Command);
            }
            var result = bridge.TryWrite(message, isSlave);

            if (result != WriteResult.Success)
            {
                var ex = Multiplexer.GetException(result, message, this);
                ConnectionMultiplexer.ThrowFailed(tcs, ex);
            }
            return(tcs.Task);
        }
Ejemplo n.º 6
0
 internal override Task <T> ExecuteAsync <T>(Message message, ResultProcessor <T> processor, ServerEndPoint server = null)
 {   // inject our expected server automatically
     if (server == null)
     {
         server = this.server;
     }
     FixFlags(message, server);
     if (!server.IsConnected)
     {
         if (message == null)
         {
             return(CompletedTask <T> .Default(asyncState));
         }
         if (message.IsFireAndForget)
         {
             return(CompletedTask <T> .Default(null));                       // F+F explicitly does not get async-state
         }
         // no need to deny exec-sync here; will be complete before they see if
         var tcs = TaskSource.Create <T>(asyncState);
         ConnectionMultiplexer.ThrowFailed(tcs, ExceptionFactory.NoConnectionAvailable(multiplexer.IncludeDetailInExceptions, message.Command, message, server));
         return(tcs.Task);
     }
     return(base.ExecuteAsync <T>(message, processor, server));
 }