示例#1
0
        public void UpdateState(BalancerState state)
        {
            lock (_lock)
            {
                if (State != state.ConnectivityState)
                {
                    ConnectionManagerLog.ChannelStateUpdated(Logger, state.ConnectivityState);
                    State = state.ConnectivityState;

                    // Iterate in reverse to reduce shifting items in the list as watchers are removed.
                    for (var i = _stateWatchers.Count - 1; i >= 0; i--)
                    {
                        var stateWatcher = _stateWatchers[i];

                        if (stateWatcher.WaitForState == null || stateWatcher.WaitForState == State)
                        {
                            stateWatcher.Tcs.SetResult(null);
                            _stateWatchers.RemoveAt(i);
                        }
                    }
                }

                if (!Equals(_picker, state.Picker))
                {
                    ConnectionManagerLog.ChannelPickerUpdated(Logger);
                    _picker = state.Picker;
                    _nextPickerTcs.SetResult(state.Picker);
                    _nextPickerTcs = new TaskCompletionSource <SubchannelPicker>(TaskCreationOptions.RunContinuationsAsynchronously);
                }
            }
        }
示例#2
0
        public void UpdateState(BalancerState state)
        {
            _controller.UpdateState(state);
            _state = state.ConnectivityState;

            NotifySubscribers();
        }