protected override async ValueTask <bool> MoveNextCore() { // NB: Earlier implementations of this operator constructed the set for the second source concurrently // with the first MoveNextAsync call on the first source. This resulted in an unexpected source of // concurrency, which isn't a great default behavior because it's very hard to suppress or control // this behavior. switch (_state) { case AsyncIteratorState.Allocated: _set = await AsyncEnumerableHelpers.ToSet(_second, _comparer, _cancellationToken).ConfigureAwait(false); _firstEnumerator = _first.GetAsyncEnumerator(_cancellationToken); _state = AsyncIteratorState.Iterating; goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: bool moveNext; do { moveNext = await _firstEnumerator.MoveNextAsync().ConfigureAwait(false); if (moveNext) { var item = _firstEnumerator.Current; if (_set.Remove(item)) { _current = item; return(true); } } } while (moveNext); await DisposeAsync().ConfigureAwait(false); break; } return(false); }
private Task <Set <TSource> > FillSetAsync(CancellationToken cancellationToken) { return(AsyncEnumerableHelpers.ToSet(_source, _comparer, cancellationToken)); }