예제 #1
0
        /// <summary>
        /// Allows explicitly requesting channel to connect without starting an RPC.
        /// Returned task completes once state Ready was seen. If the deadline is reached,
        /// or channel enters the FatalFailure state, the task is cancelled.
        /// There is no need to call this explicitly unless your use case requires that.
        /// Starting an RPC on a new channel will request connection implicitly.
        /// </summary>
        public async Task ConnectAsync(DateTime?deadline = null)
        {
            var currentState = handle.CheckConnectivityState(true);

            while (currentState != ChannelState.Ready)
            {
                if (currentState == ChannelState.FatalFailure)
                {
                    throw new OperationCanceledException("Channel has reached FatalFailure state.");
                }
                await WaitForStateChangedAsync(currentState, deadline);

                currentState = handle.CheckConnectivityState(false);
            }
        }
예제 #2
0
파일: Channel.cs 프로젝트: szzfstgit/grpc-1
 private ChannelState GetConnectivityState(bool tryToConnect)
 {
     try
     {
         return(handle.CheckConnectivityState(tryToConnect));
     }
     catch (ObjectDisposedException)
     {
         return(ChannelState.Shutdown);
     }
 }