Example #1
0
        GetNextPickerAsync(CancellationToken cancellationToken)
        {
            ConnectionManagerLog.PickWaiting(Logger);

            Debug.Assert(Monitor.IsEntered(_lock));

            var nextPickerTcs = _nextPickerTcs;

            await _nextPickerLock.WaitAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                using (cancellationToken.Register(s => ((TaskCompletionSource <SubchannelPicker?>)s !).TrySetCanceled(), nextPickerTcs))
                {
                    var nextPicker = await nextPickerTcs.Task.ConfigureAwait(false);

                    lock (_lock)
                    {
                        _nextPickerTcs = new TaskCompletionSource <SubchannelPicker>(TaskCreationOptions.RunContinuationsAsynchronously);
                    }

                    return(nextPicker);
                }
            }
            finally
            {
                _nextPickerLock.Release();
            }
        }
Example #2
0
        private Task <SubchannelPicker> GetPickerAsync(SubchannelPicker?currentPicker, CancellationToken cancellationToken)
        {
            lock (_lock)
            {
                if (_picker != null && _picker != currentPicker)
                {
                    Debug.Assert(_pickerTask != null);
                    return(_pickerTask);
                }
                else
                {
                    ConnectionManagerLog.PickWaiting(Logger);

                    return(_nextPickerTcs.Task.WaitAsync(cancellationToken));
                }
            }
        }