Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 private ChannelState GetConnectivityState(bool tryToConnect)
 {
     try
     {
         return(handle.CheckConnectivityState(tryToConnect));
     }
     catch (ObjectDisposedException)
     {
         return(ChannelState.Shutdown);
     }
 }