示例#1
0
 internal Task RemoveSubscription(RedisChannel channel, Action <RedisChannel, RedisValue> handler, CommandFlags flags, object asyncState)
 {
     lock (subscriptions)
     {
         if (subscriptions.TryGetValue(channel, out Subscription sub) && sub.Remove(handler))
         {
             subscriptions.Remove(channel);
             var task = sub.UnsubscribeFromServer(channel, flags, asyncState, false);
             if (task != null)
             {
                 return(task);
             }
         }
     }
     return(CompletedTask <bool> .Default(asyncState));
 }
示例#2
0
        internal Task RemoveAllSubscriptions(CommandFlags flags, object asyncState)
        {
            Task last = CompletedTask <bool> .Default(asyncState);

            lock (subscriptions)
            {
                foreach (var pair in subscriptions)
                {
                    pair.Value.Remove(null); // always wipes
                    var task = pair.Value.UnsubscribeFromServer(pair.Key, flags, asyncState, false);
                    if (task != null)
                    {
                        last = task;
                    }
                }
                subscriptions.Clear();
            }
            return(last);
        }
示例#3
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));
 }
示例#4
0
 internal Task AddSubscription(RedisChannel channel, Action <RedisChannel, RedisValue> handler, CommandFlags flags, object asyncState)
 {
     if (handler != null)
     {
         lock (subscriptions)
         {
             if (subscriptions.TryGetValue(channel, out Subscription sub))
             {
                 sub.Add(handler);
             }
             else
             {
                 sub = new Subscription(handler);
                 subscriptions.Add(channel, sub);
                 var task = sub.SubscribeToServer(this, channel, flags, asyncState, false);
                 if (task != null)
                 {
                     return(task);
                 }
             }
         }
     }
     return(CompletedTask <bool> .Default(asyncState));
 }