1
0
Эх сурвалжийг харах

Merge pull request #905 from dotnet/UseAsyncIterators

Remove dead code of hand-rolled iterators
Bart J.F. De Smet 6 жил өмнө
parent
commit
447c3fb735
30 өөрчлөгдсөн 5 нэмэгдсэн , 6827 устгасан
  1. 0 217
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs
  2. 0 114
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Buffer.cs
  3. 0 394
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs
  4. 0 198
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Concat.cs
  5. 0 187
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Defer.cs
  6. 0 308
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs
  7. 0 251
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Do.cs
  8. 0 287
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Expand.cs
  9. 2 129
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Finally.cs
  10. 2 78
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Generate.cs
  11. 0 57
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/IgnoreElements.cs
  12. 1 106
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Merge.cs
  13. 0 106
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Repeat.cs
  14. 0 450
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Scan.cs
  15. 0 219
      Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Using.cs
  16. 0 2
      Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/SkipLast.cs
  17. 0 56
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Cast.cs
  18. 0 85
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Except.cs
  19. 0 310
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupJoin.cs
  20. 0 85
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Intersect.cs
  21. 0 397
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Join.cs
  22. 0 60
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OfType.cs
  23. 0 210
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Select.cs
  24. 0 950
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs
  25. 0 74
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs
  26. 0 510
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipWhile.cs
  27. 0 99
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/TakeLast.cs
  28. 0 430
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/TakeWhile.cs
  29. 0 222
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs
  30. 0 236
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Zip.cs

+ 0 - 217
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -18,7 +17,6 @@ namespace System.Linq
             if (second == null)
                 throw Error.ArgumentNull(nameof(second));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -126,9 +124,6 @@ namespace System.Linq
                     await disposeLoser.ConfigureAwait(false);
                 }
             }
-#else
-            return new AmbAsyncIterator<TSource>(first, second);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Amb<TSource>(params IAsyncEnumerable<TSource>[] sources)
@@ -136,7 +131,6 @@ namespace System.Linq
             if (sources == null)
                 throw Error.ArgumentNull(nameof(sources));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -224,9 +218,6 @@ namespace System.Linq
                     await cleanupLosers.ConfigureAwait(false);
                 }
             }
-#else
-            return new AmbAsyncIteratorN<TSource>(sources);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Amb<TSource>(this IEnumerable<IAsyncEnumerable<TSource>> sources)
@@ -234,14 +225,9 @@ namespace System.Linq
             if (sources == null)
                 throw Error.ArgumentNull(nameof(sources));
 
-#if USE_ASYNC_ITERATOR
             return Amb(sources.ToArray());
-#else
-            return new AmbAsyncIteratorN<TSource>(sources.ToArray());
-#endif
         }
 
-#if USE_ASYNC_ITERATOR
         private static async Task AwaitMoveNextAsyncAndDispose<T>(Task<bool> moveNextAsync, IAsyncEnumerator<T> enumerator)
         {
             if (enumerator != null)
@@ -255,208 +241,5 @@ namespace System.Linq
                 }
             }
         }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class AmbAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IAsyncEnumerable<TSource> _first;
-            private readonly IAsyncEnumerable<TSource> _second;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public AmbAsyncIterator(IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second)
-            {
-                Debug.Assert(first != null);
-                Debug.Assert(second != null);
-
-                _first = first;
-                _second = second;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new AmbAsyncIterator<TSource>(_first, _second);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        //
-                        // REVIEW: Exceptions in any of these steps don't cause cleanup. This has been fixed in the new implementation.
-                        //
-
-                        var firstEnumerator = _first.GetAsyncEnumerator(_cancellationToken);
-                        var secondEnumerator = _second.GetAsyncEnumerator(_cancellationToken);
-
-                        var firstMoveNext = firstEnumerator.MoveNextAsync().AsTask();
-                        var secondMoveNext = secondEnumerator.MoveNextAsync().AsTask();
-
-                        var winner = await Task.WhenAny(firstMoveNext, secondMoveNext).ConfigureAwait(false);
-
-                        //
-                        // REVIEW: An alternative option is to call DisposeAsync on the other and await it, but this has two drawbacks:
-                        //
-                        // 1. Concurrent DisposeAsync while a MoveNextAsync is in flight.
-                        // 2. The winner elected by Amb is blocked to yield results until the loser unblocks.
-                        //
-                        // The approach below has one drawback, namely that exceptions raised by loser are dropped on the floor.
-                        //
-
-                        if (winner == firstMoveNext)
-                        {
-                            _enumerator = firstEnumerator;
-
-                            _ = secondMoveNext.ContinueWith(_ =>
-                            {
-                                secondEnumerator.DisposeAsync();
-                            });
-                        }
-                        else
-                        {
-                            _enumerator = secondEnumerator;
-
-                            _ = firstMoveNext.ContinueWith(_ =>
-                            {
-                                firstEnumerator.DisposeAsync();
-                            });
-                        }
-
-                        _state = AsyncIteratorState.Iterating;
-
-                        if (await winner.ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        break;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class AmbAsyncIteratorN<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IAsyncEnumerable<TSource>[] _sources;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public AmbAsyncIteratorN(IAsyncEnumerable<TSource>[] sources)
-            {
-                Debug.Assert(sources != null);
-
-                _sources = sources;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new AmbAsyncIteratorN<TSource>(_sources);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        var n = _sources.Length;
-
-                        var enumerators = new IAsyncEnumerator<TSource>[n];
-                        var moveNexts = new Task<bool>[n];
-
-                        for (var i = 0; i < n; i++)
-                        {
-                            var enumerator = _sources[i].GetAsyncEnumerator(_cancellationToken);
-
-                            enumerators[i] = enumerator;
-                            moveNexts[i] = enumerator.MoveNextAsync().AsTask();
-                        }
-
-                        var winner = await Task.WhenAny(moveNexts).ConfigureAwait(false);
-
-                        //
-                        // REVIEW: An alternative option is to call DisposeAsync on the other and await it, but this has two drawbacks:
-                        //
-                        // 1. Concurrent DisposeAsync while a MoveNextAsync is in flight.
-                        // 2. The winner elected by Amb is blocked to yield results until all losers unblocks.
-                        //
-                        // The approach below has one drawback, namely that exceptions raised by any loser are dropped on the floor.
-                        //
-
-                        var winnerIndex = Array.IndexOf(moveNexts, winner);
-
-                        _enumerator = enumerators[winnerIndex];
-
-                        for (var i = 0; i < n; i++)
-                        {
-                            if (i != winnerIndex)
-                            {
-                                _ = moveNexts[i].ContinueWith(_ =>
-                                {
-                                    enumerators[i].DisposeAsync();
-                                });
-                            }
-                        }
-
-                        _state = AsyncIteratorState.Iterating;
-
-                        if (await winner.ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        break;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 114
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Buffer.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -18,7 +17,6 @@ namespace System.Linq
             if (count <= 0)
                 throw Error.ArgumentOutOfRange(nameof(count));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<IList<TSource>> Core(CancellationToken cancellationToken)
@@ -42,9 +40,6 @@ namespace System.Linq
                     yield return buffer;
                 }
             }
-#else
-            return new BufferAsyncIterator<TSource>(source, count, count);
-#endif
         }
 
         public static IAsyncEnumerable<IList<TSource>> Buffer<TSource>(this IAsyncEnumerable<TSource> source, int count, int skip)
@@ -56,7 +51,6 @@ namespace System.Linq
             if (skip <= 0)
                 throw Error.ArgumentOutOfRange(nameof(skip));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<IList<TSource>> Core(CancellationToken cancellationToken)
@@ -88,114 +82,6 @@ namespace System.Linq
                     yield return buffers.Dequeue();
                 }
             }
-#else
-            return new BufferAsyncIterator<TSource>(source, count, skip);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class BufferAsyncIterator<TSource> : AsyncIterator<IList<TSource>>
-        {
-            private readonly int _count;
-            private readonly int _skip;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private Queue<IList<TSource>> _buffers;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-            private bool _stopped;
-
-            public BufferAsyncIterator(IAsyncEnumerable<TSource> source, int count, int skip)
-            {
-                Debug.Assert(source != null);
-
-                _source = source;
-                _count = count;
-                _skip = skip;
-            }
-
-            public override AsyncIteratorBase<IList<TSource>> Clone()
-            {
-                return new BufferAsyncIterator<TSource>(_source, _count, _skip);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                _buffers = null;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _buffers = new Queue<IList<TSource>>();
-                        _index = 0;
-                        _stopped = false;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (!_stopped)
-                            {
-                                if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    var item = _enumerator.Current;
-
-                                    if (_index++ % _skip == 0)
-                                    {
-                                        _buffers.Enqueue(new List<TSource>(_count));
-                                    }
-
-                                    foreach (var buffer in _buffers)
-                                    {
-                                        buffer.Add(item);
-                                    }
-
-                                    if (_buffers.Count > 0 && _buffers.Peek().Count == _count)
-                                    {
-                                        _current = _buffers.Dequeue();
-                                        return true;
-                                    }
-
-                                    continue; // loop
-                                }
-
-                                _stopped = true;
-                                await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                _enumerator = null;
-
-                                continue; // loop
-                            }
-
-                            if (_buffers.Count > 0)
-                            {
-                                _current = _buffers.Dequeue();
-                                return true;
-                            }
-
-                            break; // exit the while
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 394
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Runtime.ExceptionServices;
 using System.Threading;
 using System.Threading.Tasks;
@@ -25,7 +24,6 @@ namespace System.Linq
             if (handler == null)
                 throw Error.ArgumentNull(nameof(handler));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -70,9 +68,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new CatchAsyncIterator<TSource, TException>(source, handler);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Catch<TSource, TException>(this IAsyncEnumerable<TSource> source, Func<TException, ValueTask<IAsyncEnumerable<TSource>>> handler)
@@ -83,7 +78,6 @@ namespace System.Linq
             if (handler == null)
                 throw Error.ArgumentNull(nameof(handler));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -128,9 +122,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new CatchAsyncIteratorWithTask<TSource, TException>(source, handler);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -142,7 +133,6 @@ namespace System.Linq
             if (handler == null)
                 throw Error.ArgumentNull(nameof(handler));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -187,9 +177,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new CatchAsyncIteratorWithTaskAndCancellation<TSource, TException>(source, handler);
-#endif
         }
 #endif
 
@@ -221,7 +208,6 @@ namespace System.Linq
 
         private static IAsyncEnumerable<TSource> CatchCore<TSource>(IEnumerable<IAsyncEnumerable<TSource>> sources)
         {
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -261,386 +247,6 @@ namespace System.Linq
 
                 error?.Throw();
             }
-#else
-            return new CatchAsyncIterator<TSource>(sources);
-#endif
-        }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class CatchAsyncIterator<TSource, TException> : AsyncIterator<TSource> where TException : Exception
-        {
-            private readonly Func<TException, IAsyncEnumerable<TSource>> _handler;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private bool _isDone;
-
-            public CatchAsyncIterator(IAsyncEnumerable<TSource> source, Func<TException, IAsyncEnumerable<TSource>> handler)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(handler != null);
-
-                _source = source;
-                _handler = handler;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new CatchAsyncIterator<TSource, TException>(_source, _handler);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _isDone = false;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (!_isDone)
-                            {
-                                try
-                                {
-                                    if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                                    {
-                                        _current = _enumerator.Current;
-                                        return true;
-                                    }
-                                }
-                                catch (TException ex)
-                                {
-                                    // Note: Ideally we'd dispose of the previous enumerator before
-                                    // invoking the handler, but we use this order to preserve
-                                    // current behavior
-                                    var inner = _handler(ex);
-                                    var err = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    if (_enumerator != null)
-                                    {
-                                        await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _enumerator = err;
-                                    _isDone = true;
-                                    continue; // loop so we hit the catch state
-                                }
-                            }
-
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                _current = _enumerator.Current;
-                                return true;
-                            }
-
-                            break; // while
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class CatchAsyncIteratorWithTask<TSource, TException> : AsyncIterator<TSource> where TException : Exception
-        {
-            private readonly Func<TException, ValueTask<IAsyncEnumerable<TSource>>> _handler;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private bool _isDone;
-
-            public CatchAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TException, ValueTask<IAsyncEnumerable<TSource>>> handler)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(handler != null);
-
-                _source = source;
-                _handler = handler;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new CatchAsyncIteratorWithTask<TSource, TException>(_source, _handler);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _isDone = false;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (!_isDone)
-                            {
-                                try
-                                {
-                                    if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                                    {
-                                        _current = _enumerator.Current;
-                                        return true;
-                                    }
-                                }
-                                catch (TException ex)
-                                {
-                                    // Note: Ideally we'd dispose of the previous enumerator before
-                                    // invoking the handler, but we use this order to preserve
-                                    // current behavior
-                                    var inner = await _handler(ex).ConfigureAwait(false);
-                                    var err = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    if (_enumerator != null)
-                                    {
-                                        await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _enumerator = err;
-                                    _isDone = true;
-                                    continue; // loop so we hit the catch state
-                                }
-                            }
-
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                _current = _enumerator.Current;
-                                return true;
-                            }
-
-                            break; // while
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class CatchAsyncIteratorWithTaskAndCancellation<TSource, TException> : AsyncIterator<TSource> where TException : Exception
-        {
-            private readonly Func<TException, CancellationToken, ValueTask<IAsyncEnumerable<TSource>>> _handler;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private bool _isDone;
-
-            public CatchAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TException, CancellationToken, ValueTask<IAsyncEnumerable<TSource>>> handler)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(handler != null);
-
-                _source = source;
-                _handler = handler;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new CatchAsyncIteratorWithTaskAndCancellation<TSource, TException>(_source, _handler);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _isDone = false;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (!_isDone)
-                            {
-                                try
-                                {
-                                    if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                                    {
-                                        _current = _enumerator.Current;
-                                        return true;
-                                    }
-                                }
-                                catch (TException ex)
-                                {
-                                    // Note: Ideally we'd dispose of the previous enumerator before
-                                    // invoking the handler, but we use this order to preserve
-                                    // current behavior
-                                    var inner = await _handler(ex, _cancellationToken).ConfigureAwait(false);
-                                    var err = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    if (_enumerator != null)
-                                    {
-                                        await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _enumerator = err;
-                                    _isDone = true;
-                                    continue; // loop so we hit the catch state
-                                }
-                            }
-
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                _current = _enumerator.Current;
-                                return true;
-                            }
-
-                            break; // while
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
-
-        private sealed class CatchAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IEnumerable<IAsyncEnumerable<TSource>> _sources;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private ExceptionDispatchInfo _error;
-
-            private IEnumerator<IAsyncEnumerable<TSource>> _sourcesEnumerator;
-
-            public CatchAsyncIterator(IEnumerable<IAsyncEnumerable<TSource>> sources)
-            {
-                Debug.Assert(sources != null);
-
-                _sources = sources;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new CatchAsyncIterator<TSource>(_sources);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_sourcesEnumerator != null)
-                {
-                    _sourcesEnumerator.Dispose();
-                    _sourcesEnumerator = null;
-                }
-
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                _error = null;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourcesEnumerator = _sources.GetEnumerator();
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (_enumerator == null)
-                            {
-                                if (!_sourcesEnumerator.MoveNext())
-                                {
-                                    // only throw if we have an error on the last one
-                                    _error?.Throw();
-                                    break; // done, nothing else to do
-                                }
-
-                                _error = null;
-                                _enumerator = _sourcesEnumerator.Current.GetAsyncEnumerator(_cancellationToken);
-                            }
-
-                            try
-                            {
-                                if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = _enumerator.Current;
-                                    return true;
-                                }
-                            }
-                            catch (Exception ex)
-                            {
-                                // Done with the current one, go to the next
-                                await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                _enumerator = null;
-                                _error = ExceptionDispatchInfo.Capture(ex);
-                                continue;
-                            }
-
-                            break; // while
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
         }
-#endif
     }
 }

+ 0 - 198
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Concat.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -16,7 +15,6 @@ namespace System.Linq
             if (sources == null)
                 throw Error.ArgumentNull(nameof(sources));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -29,9 +27,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ConcatAsyncEnumerableAsyncIterator<TSource>(sources);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Concat<TSource>(this IEnumerable<IAsyncEnumerable<TSource>> sources)
@@ -39,7 +34,6 @@ namespace System.Linq
             if (sources == null)
                 throw Error.ArgumentNull(nameof(sources));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -52,9 +46,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return ConcatCore(sources);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Concat<TSource>(params IAsyncEnumerable<TSource>[] sources)
@@ -62,7 +53,6 @@ namespace System.Linq
             if (sources == null)
                 throw Error.ArgumentNull(nameof(sources));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -75,194 +65,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return ConcatCore(sources);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private static IAsyncEnumerable<TSource> ConcatCore<TSource>(IEnumerable<IAsyncEnumerable<TSource>> sources)
-        {
-            return new ConcatEnumerableAsyncIterator<TSource>(sources);
-        }
-
-        private sealed class ConcatEnumerableAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IEnumerable<IAsyncEnumerable<TSource>> _source;
-
-            public ConcatEnumerableAsyncIterator(IEnumerable<IAsyncEnumerable<TSource>> source)
-            {
-                Debug.Assert(source != null);
-
-                _source = source;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ConcatEnumerableAsyncIterator<TSource>(_source);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_outerEnumerator != null)
-                {
-                    _outerEnumerator.Dispose();
-                    _outerEnumerator = null;
-                }
-
-                if (_currentEnumerator != null)
-                {
-                    await _currentEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _currentEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            // State machine vars
-            private IEnumerator<IAsyncEnumerable<TSource>> _outerEnumerator;
-            private IAsyncEnumerator<TSource> _currentEnumerator;
-            private int _mode;
-
-            private const int State_OuterNext = 1;
-            private const int State_While = 4;
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _outerEnumerator = _source.GetEnumerator();
-                        _mode = State_OuterNext;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_OuterNext:
-                                if (_outerEnumerator.MoveNext())
-                                {
-                                    // make sure we dispose the previous one if we're about to replace it
-                                    if (_currentEnumerator != null)
-                                    {
-                                        await _currentEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _currentEnumerator = _outerEnumerator.Current.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_While;
-                                    goto case State_While;
-                                }
-
-                                break;
-                            case State_While:
-                                if (await _currentEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = _currentEnumerator.Current;
-                                    return true;
-                                }
-
-                                // No more on the inner enumerator, move to the next outer
-                                goto case State_OuterNext;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-
-        private sealed class ConcatAsyncEnumerableAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IAsyncEnumerable<IAsyncEnumerable<TSource>> _source;
-
-            public ConcatAsyncEnumerableAsyncIterator(IAsyncEnumerable<IAsyncEnumerable<TSource>> source)
-            {
-                Debug.Assert(source != null);
-
-                _source = source;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ConcatAsyncEnumerableAsyncIterator<TSource>(_source);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_outerEnumerator != null)
-                {
-                    await _outerEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _outerEnumerator = null;
-                }
-
-                if (_currentEnumerator != null)
-                {
-                    await _currentEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _currentEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            // State machine vars
-            private IAsyncEnumerator<IAsyncEnumerable<TSource>> _outerEnumerator;
-            private IAsyncEnumerator<TSource> _currentEnumerator;
-            private int _mode;
-
-            private const int State_OuterNext = 1;
-            private const int State_While = 4;
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _outerEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _mode = State_OuterNext;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_OuterNext:
-                                if (await _outerEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    // make sure we dispose the previous one if we're about to replace it
-                                    if (_currentEnumerator != null)
-                                    {
-                                        await _currentEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _currentEnumerator = _outerEnumerator.Current.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_While;
-                                    goto case State_While;
-                                }
-
-                                break;
-                            case State_While:
-                                if (await _currentEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = _currentEnumerator.Current;
-                                    return true;
-                                }
-
-                                // No more on the inner enumerator, move to the next outer
-                                goto case State_OuterNext;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 187
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Defer.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -16,7 +15,6 @@ namespace System.Linq
             if (factory == null)
                 throw Error.ArgumentNull(nameof(factory));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -26,9 +24,6 @@ namespace System.Linq
                     yield return item;
                 }
             }
-#else
-            return new DeferIterator<TSource>(factory);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Defer<TSource>(Func<Task<IAsyncEnumerable<TSource>>> factory)
@@ -36,7 +31,6 @@ namespace System.Linq
             if (factory == null)
                 throw Error.ArgumentNull(nameof(factory));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -46,9 +40,6 @@ namespace System.Linq
                     yield return item;
                 }
             }
-#else
-            return new AsyncDeferIterator<TSource>(factory);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -57,7 +48,6 @@ namespace System.Linq
             if (factory == null)
                 throw Error.ArgumentNull(nameof(factory));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -67,184 +57,7 @@ namespace System.Linq
                     yield return item;
                 }
             }
-#else
-            return new AsyncDeferIteratorWithCancellation<TSource>(factory);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class DeferIterator<T> : AsyncIteratorBase<T>
-        {
-            private readonly Func<IAsyncEnumerable<T>> _factory;
-            private IAsyncEnumerator<T> _enumerator;
-
-            public DeferIterator(Func<IAsyncEnumerable<T>> factory)
-            {
-                Debug.Assert(factory != null);
-
-                _factory = factory;
-            }
-
-            public override T Current => _enumerator == null ? default : _enumerator.Current;
-
-            public override AsyncIteratorBase<T> Clone()
-            {
-                return new DeferIterator<T>(_factory);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override ValueTask<bool> MoveNextCore()
-            {
-                if (_enumerator == null)
-                {
-                    return InitializeAndMoveNextAsync();
-                }
-
-                return _enumerator.MoveNextAsync();
-            }
-
-            private async ValueTask<bool> InitializeAndMoveNextAsync()
-            {
-                // NB: Using an async method to ensure any exception is reported via the task.
-
-                try
-                {
-                    _enumerator = _factory().GetAsyncEnumerator(_cancellationToken);
-                }
-                catch (Exception ex)
-                {
-                    _enumerator = Throw<T>(ex).GetAsyncEnumerator(_cancellationToken);
-                    throw;
-                }
-
-                return await _enumerator.MoveNextAsync().ConfigureAwait(false);
-            }
-        }
-
-        private sealed class AsyncDeferIterator<T> : AsyncIteratorBase<T>
-        {
-            private readonly Func<Task<IAsyncEnumerable<T>>> _factory;
-            private IAsyncEnumerator<T> _enumerator;
-
-            public AsyncDeferIterator(Func< Task<IAsyncEnumerable<T>>> factory)
-            {
-                Debug.Assert(factory != null);
-
-                _factory = factory;
-            }
-
-            public override T Current => _enumerator == null ? default : _enumerator.Current;
-
-            public override AsyncIteratorBase<T> Clone()
-            {
-                return new AsyncDeferIterator<T>(_factory);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override ValueTask<bool> MoveNextCore()
-            {
-                if (_enumerator == null)
-                {
-                    return InitializeAndMoveNextAsync();
-                }
-
-                return _enumerator.MoveNextAsync();
-            }
-
-            private async ValueTask<bool> InitializeAndMoveNextAsync()
-            {
-                try
-                {
-                    _enumerator = (await _factory().ConfigureAwait(false)).GetAsyncEnumerator(_cancellationToken);
-                }
-                catch (Exception ex)
-                {
-                    _enumerator = Throw<T>(ex).GetAsyncEnumerator(_cancellationToken);
-                    throw;
-                }
-
-                return await _enumerator.MoveNextAsync().ConfigureAwait(false);
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class AsyncDeferIteratorWithCancellation<T> : AsyncIteratorBase<T>
-        {
-            private readonly Func<CancellationToken, Task<IAsyncEnumerable<T>>> _factory;
-            private IAsyncEnumerator<T> _enumerator;
-
-            public AsyncDeferIteratorWithCancellation(Func<CancellationToken, Task<IAsyncEnumerable<T>>> factory)
-            {
-                Debug.Assert(factory != null);
-
-                _factory = factory;
-            }
-
-            public override T Current => _enumerator == null ? default : _enumerator.Current;
-
-            public override AsyncIteratorBase<T> Clone()
-            {
-                return new AsyncDeferIteratorWithCancellation<T>(_factory);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override ValueTask<bool> MoveNextCore()
-            {
-                if (_enumerator == null)
-                {
-                    return InitializeAndMoveNextAsync();
-                }
-
-                return _enumerator.MoveNextAsync();
-            }
-
-            private async ValueTask<bool> InitializeAndMoveNextAsync()
-            {
-                try
-                {
-                    _enumerator = (await _factory(_cancellationToken).ConfigureAwait(false)).GetAsyncEnumerator(_cancellationToken);
-                }
-                catch (Exception ex)
-                {
-                    _enumerator = Throw<T>(ex).GetAsyncEnumerator(_cancellationToken);
-                    throw;
-                }
-
-                return await _enumerator.MoveNextAsync().ConfigureAwait(false);
-            }
         }
-#endif
 #endif
     }
 }

+ 0 - 308
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -93,7 +92,6 @@ namespace System.Linq
 
         private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource>(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
         {
-#if USE_ASYNC_ITERATOR
             comparer ??= EqualityComparer<TSource>.Default;
 
             return AsyncEnumerable.Create(Core);
@@ -124,14 +122,10 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new DistinctUntilChangedAsyncIterator<TSource>(source, comparer);
-#endif
         }
 
         private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
         {
-#if USE_ASYNC_ITERATOR
             comparer ??= EqualityComparer<TKey>.Default;
 
             return AsyncEnumerable.Create(Core);
@@ -166,14 +160,10 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new DistinctUntilChangedAsyncIterator<TSource, TKey>(source, keySelector, comparer);
-#endif
         }
 
         private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
         {
-#if USE_ASYNC_ITERATOR
             comparer ??= EqualityComparer<TKey>.Default;
 
             return AsyncEnumerable.Create(Core);
@@ -208,15 +198,11 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new DistinctUntilChangedAsyncIteratorWithTask<TSource, TKey>(source, keySelector, comparer);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
         private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
         {
-#if USE_ASYNC_ITERATOR
             comparer ??= EqualityComparer<TKey>.Default;
 
             return AsyncEnumerable.Create(Core);
@@ -251,301 +237,7 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new DistinctUntilChangedAsyncIteratorWithTaskAndCancellation<TSource, TKey>(source, keySelector, comparer);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class DistinctUntilChangedAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IEqualityComparer<TSource> _comparer;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _currentValue;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private bool _hasCurrentValue;
-
-            public DistinctUntilChangedAsyncIterator(IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
-            {
-                Debug.Assert(source != null);
-
-                _source = source;
-                _comparer = comparer ?? EqualityComparer<TSource>.Default;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new DistinctUntilChangedAsyncIterator<TSource>(_source, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _currentValue = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            var comparerEquals = false;
-
-                            if (_hasCurrentValue)
-                            {
-                                comparerEquals = _comparer.Equals(_currentValue, item);
-                            }
-
-                            if (!_hasCurrentValue || !comparerEquals)
-                            {
-                                _hasCurrentValue = true;
-                                _currentValue = item;
-                                _current = item;
-                                return true;
-                            }
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class DistinctUntilChangedAsyncIterator<TSource, TKey> : AsyncIterator<TSource>
-        {
-            private readonly IEqualityComparer<TKey> _comparer;
-            private readonly Func<TSource, TKey> _keySelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-            private TKey _currentKeyValue;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private bool _hasCurrentKey;
-
-            public DistinctUntilChangedAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
-            {
-                _source = source;
-                _keySelector = keySelector;
-                _comparer = comparer ?? EqualityComparer<TKey>.Default;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new DistinctUntilChangedAsyncIterator<TSource, TKey>(_source, _keySelector, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _currentKeyValue = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            var key = _keySelector(item);
-                            var comparerEquals = false;
-
-                            if (_hasCurrentKey)
-                            {
-                                comparerEquals = _comparer.Equals(_currentKeyValue, key);
-                            }
-
-                            if (!_hasCurrentKey || !comparerEquals)
-                            {
-                                _hasCurrentKey = true;
-                                _currentKeyValue = key;
-                                _current = item;
-                                return true;
-                            }
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class DistinctUntilChangedAsyncIteratorWithTask<TSource, TKey> : AsyncIterator<TSource>
-        {
-            private readonly IEqualityComparer<TKey> _comparer;
-            private readonly Func<TSource, ValueTask<TKey>> _keySelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-            private TKey _currentKeyValue;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private bool _hasCurrentKey;
-
-            public DistinctUntilChangedAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
-            {
-                _source = source;
-                _keySelector = keySelector;
-                _comparer = comparer ?? EqualityComparer<TKey>.Default;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new DistinctUntilChangedAsyncIteratorWithTask<TSource, TKey>(_source, _keySelector, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _currentKeyValue = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            var key = await _keySelector(item).ConfigureAwait(false);
-                            var comparerEquals = false;
-
-                            if (_hasCurrentKey)
-                            {
-                                comparerEquals = _comparer.Equals(_currentKeyValue, key);
-                            }
-
-                            if (!_hasCurrentKey || !comparerEquals)
-                            {
-                                _hasCurrentKey = true;
-                                _currentKeyValue = key;
-                                _current = item;
-                                return true;
-                            }
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class DistinctUntilChangedAsyncIteratorWithTaskAndCancellation<TSource, TKey> : AsyncIterator<TSource>
-        {
-            private readonly IEqualityComparer<TKey> _comparer;
-            private readonly Func<TSource, CancellationToken, ValueTask<TKey>> _keySelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-            private TKey _currentKeyValue;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private bool _hasCurrentKey;
-
-            public DistinctUntilChangedAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
-            {
-                _source = source;
-                _keySelector = keySelector;
-                _comparer = comparer ?? EqualityComparer<TKey>.Default;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new DistinctUntilChangedAsyncIteratorWithTaskAndCancellation<TSource, TKey>(_source, _keySelector, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _currentKeyValue = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            var key = await _keySelector(item, _cancellationToken).ConfigureAwait(false);
-                            var comparerEquals = false;
-
-                            if (_hasCurrentKey)
-                            {
-                                comparerEquals = _comparer.Equals(_currentKeyValue, key);
-                            }
-
-                            if (!_hasCurrentKey || !comparerEquals)
-                            {
-                                _hasCurrentKey = true;
-                                _currentKeyValue = key;
-                                _current = item;
-                                return true;
-                            }
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
         }
-#endif
 #endif
     }
 }

+ 0 - 251
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Do.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -171,7 +170,6 @@ namespace System.Linq
 
         private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)
         {
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -209,14 +207,10 @@ namespace System.Linq
                     onCompleted?.Invoke();
                 }
             }
-#else
-            return new DoAsyncIterator<TSource>(source, onNext, onError, onCompleted);
-#endif
         }
 
         private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, Task> onNext, Func<Exception, Task> onError, Func<Task> onCompleted)
         {
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -257,15 +251,11 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new DoAsyncIteratorWithTask<TSource>(source, onNext, onError, onCompleted);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
         private static IAsyncEnumerable<TSource> DoCore<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, Task> onNext, Func<Exception, CancellationToken, Task> onError, Func<CancellationToken, Task> onCompleted)
         {
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -306,248 +296,7 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new DoAsyncIteratorWithTaskAndCancellation<TSource>(source, onNext, onError, onCompleted);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class DoAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Action _onCompleted;
-            private readonly Action<Exception> _onError;
-            private readonly Action<TSource> _onNext;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public DoAsyncIterator(IAsyncEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(onNext != null);
-
-                _source = source;
-                _onNext = onNext;
-                _onError = onError;
-                _onCompleted = onCompleted;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new DoAsyncIterator<TSource>(_source, _onNext, _onError, _onCompleted);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        try
-                        {
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                _current = _enumerator.Current;
-                                _onNext(_current);
-
-                                return true;
-                            }
-                        }
-                        catch (OperationCanceledException)
-                        {
-                            throw;
-                        }
-                        catch (Exception ex) when (_onError != null)
-                        {
-                            _onError(ex);
-                            throw;
-                        }
-
-                        _onCompleted?.Invoke();
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
         }
-
-        private sealed class DoAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<Task> _onCompleted;
-            private readonly Func<Exception, Task> _onError;
-            private readonly Func<TSource, Task> _onNext;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public DoAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, Task> onNext, Func<Exception, Task> onError, Func<Task> onCompleted)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(onNext != null);
-
-                _source = source;
-                _onNext = onNext;
-                _onError = onError;
-                _onCompleted = onCompleted;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new DoAsyncIteratorWithTask<TSource>(_source, _onNext, _onError, _onCompleted);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        try
-                        {
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                _current = _enumerator.Current;
-                                await _onNext(_current).ConfigureAwait(false);
-
-                                return true;
-                            }
-                        }
-                        catch (OperationCanceledException)
-                        {
-                            throw;
-                        }
-                        catch (Exception ex) when (_onError != null)
-                        {
-                            await _onError(ex).ConfigureAwait(false);
-                            throw;
-                        }
-
-                        if (_onCompleted != null)
-                        {
-                            await _onCompleted().ConfigureAwait(false);
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class DoAsyncIteratorWithTaskAndCancellation<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<CancellationToken, Task> _onCompleted;
-            private readonly Func<Exception, CancellationToken, Task> _onError;
-            private readonly Func<TSource, CancellationToken, Task> _onNext;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public DoAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, Task> onNext, Func<Exception, CancellationToken, Task> onError, Func<CancellationToken, Task> onCompleted)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(onNext != null);
-
-                _source = source;
-                _onNext = onNext;
-                _onError = onError;
-                _onCompleted = onCompleted;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new DoAsyncIteratorWithTaskAndCancellation<TSource>(_source, _onNext, _onError, _onCompleted);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        try
-                        {
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                _current = _enumerator.Current;
-                                await _onNext(_current, _cancellationToken).ConfigureAwait(false);
-
-                                return true;
-                            }
-                        }
-                        catch (OperationCanceledException)
-                        {
-                            throw;
-                        }
-                        catch (Exception ex) when (_onError != null)
-                        {
-                            await _onError(ex, _cancellationToken).ConfigureAwait(false);
-                            throw;
-                        }
-
-                        if (_onCompleted != null)
-                        {
-                            await _onCompleted(_cancellationToken).ConfigureAwait(false);
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
 #endif
     }
 }

+ 0 - 287
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Expand.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -18,7 +17,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -37,9 +35,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ExpandAsyncIterator<TSource>(source, selector);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Expand<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<IAsyncEnumerable<TSource>>> selector)
@@ -49,7 +44,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -68,9 +62,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ExpandAsyncIteratorWithTask<TSource>(source, selector);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -81,7 +72,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -100,284 +90,7 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ExpandAsyncIteratorWithTaskAndCancellation<TSource>(source, selector);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class ExpandAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, IAsyncEnumerable<TSource>> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            private Queue<IAsyncEnumerable<TSource>> _queue;
-
-            public ExpandAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, IAsyncEnumerable<TSource>> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ExpandAsyncIterator<TSource>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                _queue = null;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _queue = new Queue<IAsyncEnumerable<TSource>>();
-                        _queue.Enqueue(_source);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (_enumerator == null)
-                            {
-                                if (_queue.Count > 0)
-                                {
-                                    var src = _queue.Dequeue();
-
-                                    if (_enumerator != null)
-                                    {
-                                        await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _enumerator = src.GetAsyncEnumerator(_cancellationToken);
-
-                                    continue; // loop
-                                }
-
-                                break; // while
-                            }
-
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                var item = _enumerator.Current;
-                                var next = _selector(item);
-                                _queue.Enqueue(next);
-                                _current = item;
-                                return true;
-                            }
-
-                            await _enumerator.DisposeAsync().ConfigureAwait(false);
-                            _enumerator = null;
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class ExpandAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, ValueTask<IAsyncEnumerable<TSource>>> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            private Queue<IAsyncEnumerable<TSource>> _queue;
-
-            public ExpandAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<IAsyncEnumerable<TSource>>> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ExpandAsyncIteratorWithTask<TSource>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                _queue = null;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _queue = new Queue<IAsyncEnumerable<TSource>>();
-                        _queue.Enqueue(_source);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (_enumerator == null)
-                            {
-                                if (_queue.Count > 0)
-                                {
-                                    var src = _queue.Dequeue();
-
-                                    if (_enumerator != null)
-                                    {
-                                        await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _enumerator = src.GetAsyncEnumerator(_cancellationToken);
-
-                                    continue; // loop
-                                }
-
-                                break; // while
-                            }
-
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                var item = _enumerator.Current;
-                                var next = await _selector(item).ConfigureAwait(false);
-                                _queue.Enqueue(next);
-                                _current = item;
-                                return true;
-                            }
-
-                            await _enumerator.DisposeAsync().ConfigureAwait(false);
-                            _enumerator = null;
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class ExpandAsyncIteratorWithTaskAndCancellation<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, CancellationToken, ValueTask<IAsyncEnumerable<TSource>>> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            private Queue<IAsyncEnumerable<TSource>> _queue;
-
-            public ExpandAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<IAsyncEnumerable<TSource>>> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ExpandAsyncIteratorWithTaskAndCancellation<TSource>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                _queue = null;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _queue = new Queue<IAsyncEnumerable<TSource>>();
-                        _queue.Enqueue(_source);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (_enumerator == null)
-                            {
-                                if (_queue.Count > 0)
-                                {
-                                    var src = _queue.Dequeue();
-
-                                    if (_enumerator != null)
-                                    {
-                                        await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _enumerator = src.GetAsyncEnumerator(_cancellationToken);
-
-                                    continue; // loop
-                                }
-
-                                break; // while
-                            }
-
-                            if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                            {
-                                var item = _enumerator.Current;
-                                var next = await _selector(item, _cancellationToken).ConfigureAwait(false);
-                                _queue.Enqueue(next);
-                                _current = item;
-                                return true;
-                            }
-
-                            await _enumerator.DisposeAsync().ConfigureAwait(false);
-                            _enumerator = null;
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
         }
-#endif
 #endif
     }
 }

+ 2 - 129
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Finally.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -18,7 +17,6 @@ namespace System.Linq
             if (finallyAction == null)
                 throw Error.ArgumentNull(nameof(finallyAction));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -35,9 +33,6 @@ namespace System.Linq
                     finallyAction();
                 }
             }
-#else
-            return new FinallyAsyncIterator<TSource>(source, finallyAction);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Finally<TSource>(this IAsyncEnumerable<TSource> source, Func<Task> finallyAction)
@@ -47,7 +42,6 @@ namespace System.Linq
             if (finallyAction == null)
                 throw Error.ArgumentNull(nameof(finallyAction));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -61,132 +55,11 @@ namespace System.Linq
                 }
                 finally
                 {
-                    await finallyAction().ConfigureAwait(false);
-                }
-            }
-#else
-            return new FinallyAsyncIteratorWithTask<TSource>(source, finallyAction);
-#endif
-        }
-
-        // REVIEW: No cancellation support for finally action.
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class FinallyAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Action _finallyAction;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public FinallyAsyncIterator(IAsyncEnumerable<TSource> source, Action finallyAction)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(finallyAction != null);
-
-                _source = source;
-                _finallyAction = finallyAction;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new FinallyAsyncIterator<TSource>(_source, _finallyAction);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-
-                    _finallyAction();
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-
-        private sealed class FinallyAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<Task> _finallyAction;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public FinallyAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<Task> finallyAction)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(finallyAction != null);
-
-                _source = source;
-                _finallyAction = finallyAction;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new FinallyAsyncIteratorWithTask<TSource>(_source, _finallyAction);
-            }
+                    // REVIEW: No cancellation support for finally action.
 
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-
-                    await _finallyAction().ConfigureAwait(false);
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
+                    await finallyAction().ConfigureAwait(false);
                 }
-
-                return false;
             }
         }
-#endif
     }
 }

+ 2 - 78
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Generate.cs

@@ -3,14 +3,14 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
-using System.Threading.Tasks;
 
 namespace System.Linq
 {
     public static partial class AsyncEnumerableEx
     {
+        // REVIEW: Add async variant?
+
         public static IAsyncEnumerable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector)
         {
             if (condition == null)
@@ -20,7 +20,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
 #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
@@ -34,81 +33,6 @@ namespace System.Linq
                 }
             }
 #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
-#else
-            return new GenerateAsyncIterator<TState, TResult>(initialState, condition, iterate, resultSelector);
-#endif
-        }
-
-        // REVIEW: Add async variant?
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class GenerateAsyncIterator<TState, TResult> : AsyncIterator<TResult>
-        {
-            private readonly Func<TState, bool> _condition;
-            private readonly TState _initialState;
-            private readonly Func<TState, TState> _iterate;
-            private readonly Func<TState, TResult> _resultSelector;
-
-            private TState _currentState;
-
-            private bool _started;
-
-            public GenerateAsyncIterator(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector)
-            {
-                Debug.Assert(condition != null);
-                Debug.Assert(iterate != null);
-                Debug.Assert(resultSelector != null);
-
-                _initialState = initialState;
-                _condition = condition;
-                _iterate = iterate;
-                _resultSelector = resultSelector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new GenerateAsyncIterator<TState, TResult>(_initialState, _condition, _iterate, _resultSelector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                _currentState = default;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _started = false;
-                        _currentState = _initialState;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (_started)
-                        {
-                            _currentState = _iterate(_currentState);
-                        }
-
-                        _started = true;
-
-                        if (_condition(_currentState))
-                        {
-                            _current = _resultSelector(_currentState);
-                            return true;
-                        }
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-
-                return false;
-            }
         }
-#endif
     }
 }

+ 0 - 57
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/IgnoreElements.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -16,7 +15,6 @@ namespace System.Linq
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -27,61 +25,6 @@ namespace System.Linq
 
                 yield break;
             }
-#else
-            return new IgnoreElementsAsyncIterator<TSource>(source);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class IgnoreElementsAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IAsyncEnumerable<TSource> _source;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public IgnoreElementsAsyncIterator(IAsyncEnumerable<TSource> source)
-            {
-                Debug.Assert(source != null);
-
-                _source = source;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new IgnoreElementsAsyncIterator<TSource>(_source);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
     }
 }

+ 1 - 106
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Merge.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -170,7 +169,7 @@ namespace System.Linq
                     }
                 }
             }
-#elif USE_ASYNC_ITERATOR
+#else
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -294,8 +293,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new MergeAsyncIterator<TSource>(sources);
 #endif
         }
 
@@ -338,107 +335,5 @@ namespace System.Linq
 
             return sources.SelectMany(source => source);
         }
-
-        private sealed class MergeAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IAsyncEnumerable<TSource>[] _sources;
-
-            private IAsyncEnumerator<TSource>[] _enumerators;
-            private Task<bool>[] _moveNexts;
-            private int _active;
-
-            public MergeAsyncIterator(IAsyncEnumerable<TSource>[] sources)
-            {
-                Debug.Assert(sources != null);
-
-                _sources = sources;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new MergeAsyncIterator<TSource>(_sources);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerators != null)
-                {
-                    var n = _enumerators.Length;
-
-                    var disposes = new ValueTask[n];
-
-                    for (var i = 0; i < n; i++)
-                    {
-                        var dispose = _enumerators[i].DisposeAsync();
-                        disposes[i] = dispose;
-                    }
-
-                    await Task.WhenAll(disposes.Select(t => t.AsTask())).ConfigureAwait(false);
-                    _enumerators = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        var n = _sources.Length;
-
-                        _enumerators = new IAsyncEnumerator<TSource>[n];
-                        _moveNexts = new Task<bool>[n];
-                        _active = n;
-
-                        for (var i = 0; i < n; i++)
-                        {
-                            var enumerator = _sources[i].GetAsyncEnumerator(_cancellationToken);
-                            _enumerators[i] = enumerator;
-                            _moveNexts[i] = enumerator.MoveNextAsync().AsTask();
-                        }
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (_active > 0)
-                        {
-                            //
-                            // REVIEW: This approach does have a bias towards giving sources on the left
-                            //         priority over sources on the right when yielding values. We may
-                            //         want to consider a "prefer fairness" option.
-                            //
-
-                            var moveNext = await Task.WhenAny(_moveNexts).ConfigureAwait(false);
-
-                            // REVIEW: This seems wrong. AsTask can return the original Task<bool> (if the ValueTask<bool>
-                            //         is wrapping one) or return a singleton instance for true and false, at which point
-                            //         the use of IndexOf may pick an element closer to the start of the array because of
-                            //         reference equality checks and aliasing effects. See GetTaskForResult in the BCL.
-
-                            var index = Array.IndexOf(_moveNexts, moveNext);
-
-                            if (!await moveNext.ConfigureAwait(false))
-                            {
-                                _moveNexts[index] = TaskExt.Never;
-                                _active--;
-                            }
-                            else
-                            {
-                                var enumerator = _enumerators[index];
-                                _current = enumerator.Current;
-                                _moveNexts[index] = enumerator.MoveNextAsync().AsTask();
-                                return true;
-                            }
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
     }
 }

+ 0 - 106
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Repeat.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -13,7 +12,6 @@ namespace System.Linq
     {
         public static IAsyncEnumerable<TResult> Repeat<TResult>(TResult element)
         {
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
 #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
@@ -27,9 +25,6 @@ namespace System.Linq
                 }
             }
 #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
-#else
-            return new RepeatElementAsyncIterator<TResult>(element);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Repeat<TSource>(this IAsyncEnumerable<TSource> source)
@@ -37,7 +32,6 @@ namespace System.Linq
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -50,9 +44,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new RepeatSequenceAsyncIterator<TSource>(source, -1);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Repeat<TSource>(this IAsyncEnumerable<TSource> source, int count)
@@ -62,7 +53,6 @@ namespace System.Linq
             if (count < 0)
                 throw Error.ArgumentOutOfRange(nameof(count));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -75,102 +65,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new RepeatSequenceAsyncIterator<TSource>(source, count);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class RepeatElementAsyncIterator<TResult> : AsyncIterator<TResult>
-        {
-            private readonly TResult _element;
-
-            public RepeatElementAsyncIterator(TResult element) => _element = element;
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new RepeatElementAsyncIterator<TResult>(_element);
-            }
-
-            protected override ValueTask<bool> MoveNextCore()
-            {
-                _cancellationToken.ThrowIfCancellationRequested();
-
-                _current = _element;
-                return new ValueTask<bool>(true);
-            }
-        }
-
-        private sealed class RepeatSequenceAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly int _count;
-            private readonly bool _isInfinite;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private int _currentCount;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public RepeatSequenceAsyncIterator(IAsyncEnumerable<TSource> source, int count)
-            {
-                Debug.Assert(source != null);
-
-                _source = source;
-                _count = count;
-                _isInfinite = count < 0;
-                _currentCount = count;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new RepeatSequenceAsyncIterator<TSource>(_source, _count);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-
-                        if (_enumerator != null)
-                        {
-                            await _enumerator.DisposeAsync().ConfigureAwait(false);
-                            _enumerator = null;
-                        }
-
-                        if (!_isInfinite && _currentCount-- == 0)
-                            break;
-
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        goto case AsyncIteratorState.Allocated;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 450
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Scan.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -22,7 +21,6 @@ namespace System.Linq
             if (accumulator == null)
                 throw Error.ArgumentNull(nameof(accumulator));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -44,9 +42,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ScanAsyncEnumerable<TSource>(source, accumulator);
-#endif
         }
 
         public static IAsyncEnumerable<TAccumulate> Scan<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)
@@ -56,7 +51,6 @@ namespace System.Linq
             if (accumulator == null)
                 throw Error.ArgumentNull(nameof(accumulator));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TAccumulate> Core(CancellationToken cancellationToken)
@@ -70,9 +64,6 @@ namespace System.Linq
                     yield return res;
                 }
             }
-#else
-            return new ScanAsyncEnumerable<TSource, TAccumulate>(source, seed, accumulator);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Scan<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, ValueTask<TSource>> accumulator)
@@ -82,7 +73,6 @@ namespace System.Linq
             if (accumulator == null)
                 throw Error.ArgumentNull(nameof(accumulator));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -104,9 +94,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ScanAsyncEnumerableWithTask<TSource>(source, accumulator);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -117,7 +104,6 @@ namespace System.Linq
             if (accumulator == null)
                 throw Error.ArgumentNull(nameof(accumulator));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -139,9 +125,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ScanAsyncEnumerableWithTaskAndCancellation<TSource>(source, accumulator);
-#endif
         }
 #endif
 
@@ -152,7 +135,6 @@ namespace System.Linq
             if (accumulator == null)
                 throw Error.ArgumentNull(nameof(accumulator));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TAccumulate> Core(CancellationToken cancellationToken)
@@ -166,9 +148,6 @@ namespace System.Linq
                     yield return res;
                 }
             }
-#else
-            return new ScanAsyncEnumerableWithTask<TSource, TAccumulate>(source, seed, accumulator);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -179,7 +158,6 @@ namespace System.Linq
             if (accumulator == null)
                 throw Error.ArgumentNull(nameof(accumulator));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TAccumulate> Core(CancellationToken cancellationToken)
@@ -193,435 +171,7 @@ namespace System.Linq
                     yield return res;
                 }
             }
-#else
-            return new ScanAsyncEnumerableWithTaskAndCancellation<TSource, TAccumulate>(source, seed, accumulator);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class ScanAsyncEnumerable<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, TSource, TSource> _accumulator;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _accumulated;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            private bool _hasSeed;
-
-            public ScanAsyncEnumerable(IAsyncEnumerable<TSource> source, Func<TSource, TSource, TSource> accumulator)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(accumulator != null);
-
-                _source = source;
-                _accumulator = accumulator;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ScanAsyncEnumerable<TSource>(_source, _accumulator);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _accumulated = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _hasSeed = false;
-                        _accumulated = default;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            if (!_hasSeed)
-                            {
-                                _hasSeed = true;
-                                _accumulated = item;
-                                continue; // loop
-                            }
-
-                            _accumulated = _accumulator(_accumulated, item);
-                            _current = _accumulated;
-                            return true;
-                        }
-
-                        break; // case
-
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
         }
-
-        private sealed class ScanAsyncEnumerable<TSource, TAccumulate> : AsyncIterator<TAccumulate>
-        {
-            private readonly Func<TAccumulate, TSource, TAccumulate> _accumulator;
-            private readonly TAccumulate _seed;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TAccumulate _accumulated;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public ScanAsyncEnumerable(IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(accumulator != null);
-
-                _source = source;
-                _seed = seed;
-                _accumulator = accumulator;
-            }
-
-            public override AsyncIteratorBase<TAccumulate> Clone()
-            {
-                return new ScanAsyncEnumerable<TSource, TAccumulate>(_source, _seed, _accumulator);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _accumulated = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _accumulated = _seed;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            _accumulated = _accumulator(_accumulated, item);
-                            _current = _accumulated;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class ScanAsyncEnumerableWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, TSource, ValueTask<TSource>> _accumulator;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _accumulated;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            private bool _hasSeed;
-
-            public ScanAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, Func<TSource, TSource, ValueTask<TSource>> accumulator)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(accumulator != null);
-
-                _source = source;
-                _accumulator = accumulator;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ScanAsyncEnumerableWithTask<TSource>(_source, _accumulator);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _accumulated = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _hasSeed = false;
-                        _accumulated = default;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            if (!_hasSeed)
-                            {
-                                _hasSeed = true;
-                                _accumulated = item;
-                                continue; // loop
-                            }
-
-                            _accumulated = await _accumulator(_accumulated, item).ConfigureAwait(false);
-                            _current = _accumulated;
-                            return true;
-                        }
-
-                        break; // case
-
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class ScanAsyncEnumerableWithTaskAndCancellation<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, TSource, CancellationToken, ValueTask<TSource>> _accumulator;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _accumulated;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            private bool _hasSeed;
-
-            public ScanAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, TSource, CancellationToken, ValueTask<TSource>> accumulator)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(accumulator != null);
-
-                _source = source;
-                _accumulator = accumulator;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ScanAsyncEnumerableWithTaskAndCancellation<TSource>(_source, _accumulator);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _accumulated = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _hasSeed = false;
-                        _accumulated = default;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            if (!_hasSeed)
-                            {
-                                _hasSeed = true;
-                                _accumulated = item;
-                                continue; // loop
-                            }
-
-                            _accumulated = await _accumulator(_accumulated, item, _cancellationToken).ConfigureAwait(false);
-                            _current = _accumulated;
-                            return true;
-                        }
-
-                        break; // case
-
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
-
-        private sealed class ScanAsyncEnumerableWithTask<TSource, TAccumulate> : AsyncIterator<TAccumulate>
-        {
-            private readonly Func<TAccumulate, TSource, ValueTask<TAccumulate>> _accumulator;
-            private readonly TAccumulate _seed;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TAccumulate _accumulated;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public ScanAsyncEnumerableWithTask(IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, ValueTask<TAccumulate>> accumulator)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(accumulator != null);
-
-                _source = source;
-                _seed = seed;
-                _accumulator = accumulator;
-            }
-
-            public override AsyncIteratorBase<TAccumulate> Clone()
-            {
-                return new ScanAsyncEnumerableWithTask<TSource, TAccumulate>(_source, _seed, _accumulator);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _accumulated = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _accumulated = _seed;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            _accumulated = await _accumulator(_accumulated, item).ConfigureAwait(false);
-                            _current = _accumulated;
-                            return true;
-                        }
-
-                        break;
-
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class ScanAsyncEnumerableWithTaskAndCancellation<TSource, TAccumulate> : AsyncIterator<TAccumulate>
-        {
-            private readonly Func<TAccumulate, TSource, CancellationToken, ValueTask<TAccumulate>> _accumulator;
-            private readonly TAccumulate _seed;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TAccumulate _accumulated;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public ScanAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, ValueTask<TAccumulate>> accumulator)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(accumulator != null);
-
-                _source = source;
-                _seed = seed;
-                _accumulator = accumulator;
-            }
-
-            public override AsyncIteratorBase<TAccumulate> Clone()
-            {
-                return new ScanAsyncEnumerableWithTaskAndCancellation<TSource, TAccumulate>(_source, _seed, _accumulator);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                    _accumulated = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _accumulated = _seed;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            _accumulated = await _accumulator(_accumulated, item, _cancellationToken).ConfigureAwait(false);
-                            _current = _accumulated;
-                            return true;
-                        }
-
-                        break;
-
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
 #endif
     }
 }

+ 0 - 219
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Using.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -20,7 +19,6 @@ namespace System.Linq
             if (enumerableFactory == null)
                 throw Error.ArgumentNull(nameof(enumerableFactory));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -33,9 +31,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new UsingAsyncIterator<TSource, TResource>(resourceFactory, enumerableFactory);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> Using<TSource, TResource>(Func<Task<TResource>> resourceFactory, Func<TResource, ValueTask<IAsyncEnumerable<TSource>>> enumerableFactory) where TResource : IDisposable
@@ -45,7 +40,6 @@ namespace System.Linq
             if (enumerableFactory == null)
                 throw Error.ArgumentNull(nameof(enumerableFactory));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -58,9 +52,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new UsingAsyncIteratorWithTask<TSource, TResource>(resourceFactory, enumerableFactory);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -71,7 +62,6 @@ namespace System.Linq
             if (enumerableFactory == null)
                 throw Error.ArgumentNull(nameof(enumerableFactory));
 
-#if USE_ASYNC_ITERATOR
             return AsyncEnumerable.Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -84,216 +74,7 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new UsingAsyncIteratorWithTaskAndCancellation<TSource, TResource>(resourceFactory, enumerableFactory);
-#endif
         }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class UsingAsyncIterator<TSource, TResource> : AsyncIterator<TSource> where TResource : IDisposable
-        {
-            private readonly Func<TResource, IAsyncEnumerable<TSource>> _enumerableFactory;
-            private readonly Func<TResource> _resourceFactory;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private TResource _resource;
-
-            public UsingAsyncIterator(Func<TResource> resourceFactory, Func<TResource, IAsyncEnumerable<TSource>> enumerableFactory)
-            {
-                Debug.Assert(resourceFactory != null);
-                Debug.Assert(enumerableFactory != null);
-
-                _resourceFactory = resourceFactory;
-                _enumerableFactory = enumerableFactory;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new UsingAsyncIterator<TSource, TResource>(_resourceFactory, _enumerableFactory);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                if (_resource != null)
-                {
-                    _resource.Dispose();
-                    _resource = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                // NB: Earlier behavior of this operator was more eager, causing the resource factory to be called upon calling
-                //     GetAsyncEnumerator. This is inconsistent with asynchronous "using" and with a C# 8.0 async iterator with
-                //     a using statement inside, so this logic got moved to MoveNextAsync instead.
-
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _resource = _resourceFactory();
-                        _enumerator = _enumerableFactory(_resource).GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-
-        private sealed class UsingAsyncIteratorWithTask<TSource, TResource> : AsyncIterator<TSource> where TResource : IDisposable
-        {
-            private readonly Func<TResource, ValueTask<IAsyncEnumerable<TSource>>> _enumerableFactory;
-            private readonly Func<Task<TResource>> _resourceFactory;
-
-            private IAsyncEnumerable<TSource> _enumerable;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private TResource _resource;
-
-            public UsingAsyncIteratorWithTask(Func<Task<TResource>> resourceFactory, Func<TResource, ValueTask<IAsyncEnumerable<TSource>>> enumerableFactory)
-            {
-                Debug.Assert(resourceFactory != null);
-                Debug.Assert(enumerableFactory != null);
-
-                _resourceFactory = resourceFactory;
-                _enumerableFactory = enumerableFactory;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new UsingAsyncIteratorWithTask<TSource, TResource>(_resourceFactory, _enumerableFactory);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                if (_resource != null)
-                {
-                    _resource.Dispose();
-                    _resource = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _resource = await _resourceFactory().ConfigureAwait(false);
-                        _enumerable = await _enumerableFactory(_resource).ConfigureAwait(false);
-
-                        _enumerator = _enumerable.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class UsingAsyncIteratorWithTaskAndCancellation<TSource, TResource> : AsyncIterator<TSource> where TResource : IDisposable
-        {
-            private readonly Func<TResource, CancellationToken, ValueTask<IAsyncEnumerable<TSource>>> _enumerableFactory;
-            private readonly Func<CancellationToken, Task<TResource>> _resourceFactory;
-
-            private IAsyncEnumerable<TSource> _enumerable;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private TResource _resource;
-
-            public UsingAsyncIteratorWithTaskAndCancellation(Func<CancellationToken, Task<TResource>> resourceFactory, Func<TResource, CancellationToken, ValueTask<IAsyncEnumerable<TSource>>> enumerableFactory)
-            {
-                Debug.Assert(resourceFactory != null);
-                Debug.Assert(enumerableFactory != null);
-
-                _resourceFactory = resourceFactory;
-                _enumerableFactory = enumerableFactory;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new UsingAsyncIteratorWithTaskAndCancellation<TSource, TResource>(_resourceFactory, _enumerableFactory);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                if (_resource != null)
-                {
-                    _resource.Dispose();
-                    _resource = default;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _resource = await _resourceFactory(_cancellationToken).ConfigureAwait(false);
-                        _enumerable = await _enumerableFactory(_resource, _cancellationToken).ConfigureAwait(false);
-
-                        _enumerator = _enumerable.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
 #endif
     }
 }

+ 0 - 2
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/SkipLast.cs

@@ -63,7 +63,6 @@ namespace Tests
             await NoNextAsync(e);
         }
 
-#if USE_ASYNC_ITERATOR
         [Fact]
         public void SkipLast_Zero_NoAlias()
         {
@@ -78,6 +77,5 @@ namespace Tests
             await Task.Yield();
             yield return 1;
         }
-#endif
     }
 }

+ 0 - 56
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Cast.cs

@@ -23,7 +23,6 @@ namespace System.Linq
                 return typedSource;
             }
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -33,61 +32,6 @@ namespace System.Linq
                     yield return (TResult)obj;
                 }
             }
-#else
-            return new CastAsyncIterator<TResult>(source);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class CastAsyncIterator<TResult> : AsyncIterator<TResult>
-        {
-            private readonly IAsyncEnumerable<object> _source;
-            private IAsyncEnumerator<object> _enumerator;
-
-            public CastAsyncIterator(IAsyncEnumerable<object> source)
-            {
-                _source = source;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new CastAsyncIterator<TResult>(_source);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = (TResult)_enumerator.Current;
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 85
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Except.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -21,7 +20,6 @@ namespace System.Linq
             if (second == null)
                 throw Error.ArgumentNull(nameof(second));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -41,89 +39,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ExceptAsyncIterator<TSource>(first, second, comparer);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class ExceptAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IEqualityComparer<TSource> _comparer;
-            private readonly IAsyncEnumerable<TSource> _first;
-            private readonly IAsyncEnumerable<TSource> _second;
-
-            private IAsyncEnumerator<TSource> _firstEnumerator;
-            private Set<TSource> _set;
-
-            public ExceptAsyncIterator(IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
-            {
-                Debug.Assert(first != null);
-                Debug.Assert(second != null);
-
-                _first = first;
-                _second = second;
-                _comparer = comparer;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new ExceptAsyncIterator<TSource>(_first, _second, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_firstEnumerator != null)
-                {
-                    await _firstEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _firstEnumerator = null;
-                }
-
-                _set = null;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            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.Add(item))
-                                {
-                                    _current = item;
-                                    return true;
-                                }
-                            }
-                        } while (moveNext);
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 310
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupJoin.cs

@@ -26,7 +26,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -47,9 +46,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new GroupJoinAsyncEnumerable<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
-#endif
         }
 
         internal static IAsyncEnumerable<TResult> GroupJoinAwaitCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>> resultSelector) =>
@@ -68,7 +64,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -89,9 +84,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new GroupJoinAsyncEnumerableWithTask<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -111,7 +103,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -132,308 +123,7 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new GroupJoinAsyncEnumerableWithTaskAndCancellation<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class GroupJoinAsyncEnumerable<TOuter, TInner, TKey, TResult> : IAsyncEnumerable<TResult>
-        {
-            private readonly IEqualityComparer<TKey> _comparer;
-            private readonly IAsyncEnumerable<TInner> _inner;
-            private readonly Func<TInner, TKey> _innerKeySelector;
-            private readonly IAsyncEnumerable<TOuter> _outer;
-            private readonly Func<TOuter, TKey> _outerKeySelector;
-            private readonly Func<TOuter, IAsyncEnumerable<TInner>, TResult> _resultSelector;
-
-            public GroupJoinAsyncEnumerable(
-                IAsyncEnumerable<TOuter> outer,
-                IAsyncEnumerable<TInner> inner,
-                Func<TOuter, TKey> outerKeySelector,
-                Func<TInner, TKey> innerKeySelector,
-                Func<TOuter, IAsyncEnumerable<TInner>, TResult> resultSelector,
-                IEqualityComparer<TKey> comparer)
-            {
-                _outer = outer;
-                _inner = inner;
-                _outerKeySelector = outerKeySelector;
-                _innerKeySelector = innerKeySelector;
-                _resultSelector = resultSelector;
-                _comparer = comparer;
-            }
-
-            public IAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken)
-            {
-                cancellationToken.ThrowIfCancellationRequested(); // NB: [LDM-2018-11-28] Equivalent to async iterator behavior.
-
-                return new GroupJoinAsyncEnumerator(
-                    _outer.GetAsyncEnumerator(cancellationToken),
-                    _inner,
-                    _outerKeySelector,
-                    _innerKeySelector,
-                    _resultSelector,
-                    _comparer,
-                    cancellationToken);
-            }
-
-            private sealed class GroupJoinAsyncEnumerator : IAsyncEnumerator<TResult>
-            {
-                private readonly IEqualityComparer<TKey> _comparer;
-                private readonly IAsyncEnumerable<TInner> _inner;
-                private readonly Func<TInner, TKey> _innerKeySelector;
-                private readonly IAsyncEnumerator<TOuter> _outer;
-                private readonly Func<TOuter, TKey> _outerKeySelector;
-                private readonly Func<TOuter, IAsyncEnumerable<TInner>, TResult> _resultSelector;
-                private readonly CancellationToken _cancellationToken;
-
-                private Internal.Lookup<TKey, TInner> _lookup;
-
-                public GroupJoinAsyncEnumerator(
-                    IAsyncEnumerator<TOuter> outer,
-                    IAsyncEnumerable<TInner> inner,
-                    Func<TOuter, TKey> outerKeySelector,
-                    Func<TInner, TKey> innerKeySelector,
-                    Func<TOuter, IAsyncEnumerable<TInner>, TResult> resultSelector,
-                    IEqualityComparer<TKey> comparer,
-                    CancellationToken cancellationToken)
-                {
-                    _outer = outer;
-                    _inner = inner;
-                    _outerKeySelector = outerKeySelector;
-                    _innerKeySelector = innerKeySelector;
-                    _resultSelector = resultSelector;
-                    _comparer = comparer;
-                    _cancellationToken = cancellationToken;
-                }
-
-                public async ValueTask<bool> MoveNextAsync()
-                {
-                    // nothing to do 
-                    if (!await _outer.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        return false;
-                    }
-
-                    if (_lookup == null)
-                    {
-                        _lookup = await Internal.Lookup<TKey, TInner>.CreateForJoinAsync(_inner, _innerKeySelector, _comparer, _cancellationToken).ConfigureAwait(false);
-                    }
-
-                    var item = _outer.Current;
-
-                    var outerKey = _outerKeySelector(item);
-                    var inner = _lookup[outerKey].ToAsyncEnumerable();
-
-                    Current = _resultSelector(item, inner);
-
-                    return true;
-                }
-
-                public TResult Current { get; private set; }
-
-                public ValueTask DisposeAsync() => _outer.DisposeAsync();
-            }
         }
-
-        private sealed class GroupJoinAsyncEnumerableWithTask<TOuter, TInner, TKey, TResult> : IAsyncEnumerable<TResult>
-        {
-            private readonly IEqualityComparer<TKey> _comparer;
-            private readonly IAsyncEnumerable<TInner> _inner;
-            private readonly Func<TInner, ValueTask<TKey>> _innerKeySelector;
-            private readonly IAsyncEnumerable<TOuter> _outer;
-            private readonly Func<TOuter, ValueTask<TKey>> _outerKeySelector;
-            private readonly Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>> _resultSelector;
-
-            public GroupJoinAsyncEnumerableWithTask(
-                IAsyncEnumerable<TOuter> outer,
-                IAsyncEnumerable<TInner> inner,
-                Func<TOuter, ValueTask<TKey>> outerKeySelector,
-                Func<TInner, ValueTask<TKey>> innerKeySelector,
-                Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>> resultSelector,
-                IEqualityComparer<TKey> comparer)
-            {
-                _outer = outer;
-                _inner = inner;
-                _outerKeySelector = outerKeySelector;
-                _innerKeySelector = innerKeySelector;
-                _resultSelector = resultSelector;
-                _comparer = comparer;
-            }
-
-            public IAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken)
-            {
-                cancellationToken.ThrowIfCancellationRequested(); // NB: [LDM-2018-11-28] Equivalent to async iterator behavior.
-
-                return new GroupJoinAsyncEnumeratorWithTask(
-                    _outer.GetAsyncEnumerator(cancellationToken),
-                    _inner,
-                    _outerKeySelector,
-                    _innerKeySelector,
-                    _resultSelector,
-                    _comparer,
-                    cancellationToken);
-            }
-
-            private sealed class GroupJoinAsyncEnumeratorWithTask : IAsyncEnumerator<TResult>
-            {
-                private readonly IEqualityComparer<TKey> _comparer;
-                private readonly IAsyncEnumerable<TInner> _inner;
-                private readonly Func<TInner, ValueTask<TKey>> _innerKeySelector;
-                private readonly IAsyncEnumerator<TOuter> _outer;
-                private readonly Func<TOuter, ValueTask<TKey>> _outerKeySelector;
-                private readonly Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>> _resultSelector;
-                private readonly CancellationToken _cancellationToken;
-
-                private Internal.LookupWithTask<TKey, TInner> _lookup;
-
-                public GroupJoinAsyncEnumeratorWithTask(
-                    IAsyncEnumerator<TOuter> outer,
-                    IAsyncEnumerable<TInner> inner,
-                    Func<TOuter, ValueTask<TKey>> outerKeySelector,
-                    Func<TInner, ValueTask<TKey>> innerKeySelector,
-                    Func<TOuter, IAsyncEnumerable<TInner>, ValueTask<TResult>> resultSelector,
-                    IEqualityComparer<TKey> comparer,
-                    CancellationToken cancellationToken)
-                {
-                    _outer = outer;
-                    _inner = inner;
-                    _outerKeySelector = outerKeySelector;
-                    _innerKeySelector = innerKeySelector;
-                    _resultSelector = resultSelector;
-                    _comparer = comparer;
-                    _cancellationToken = cancellationToken;
-                }
-
-                public async ValueTask<bool> MoveNextAsync()
-                {
-                    // nothing to do 
-                    if (!await _outer.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        return false;
-                    }
-
-                    if (_lookup == null)
-                    {
-                        _lookup = await Internal.LookupWithTask<TKey, TInner>.CreateForJoinAsync(_inner, _innerKeySelector, _comparer, _cancellationToken).ConfigureAwait(false);
-                    }
-
-                    var item = _outer.Current;
-
-                    var outerKey = await _outerKeySelector(item).ConfigureAwait(false);
-                    var inner = _lookup[outerKey].ToAsyncEnumerable();
-
-                    Current = await _resultSelector(item, inner).ConfigureAwait(false);
-
-                    return true;
-                }
-
-                public TResult Current { get; private set; }
-
-                public ValueTask DisposeAsync() => _outer.DisposeAsync();
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class GroupJoinAsyncEnumerableWithTaskAndCancellation<TOuter, TInner, TKey, TResult> : IAsyncEnumerable<TResult>
-        {
-            private readonly IEqualityComparer<TKey> _comparer;
-            private readonly IAsyncEnumerable<TInner> _inner;
-            private readonly Func<TInner, CancellationToken, ValueTask<TKey>> _innerKeySelector;
-            private readonly IAsyncEnumerable<TOuter> _outer;
-            private readonly Func<TOuter, CancellationToken, ValueTask<TKey>> _outerKeySelector;
-            private readonly Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>> _resultSelector;
-
-            public GroupJoinAsyncEnumerableWithTaskAndCancellation(
-                IAsyncEnumerable<TOuter> outer,
-                IAsyncEnumerable<TInner> inner,
-                Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector,
-                Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector,
-                Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>> resultSelector,
-                IEqualityComparer<TKey> comparer)
-            {
-                _outer = outer;
-                _inner = inner;
-                _outerKeySelector = outerKeySelector;
-                _innerKeySelector = innerKeySelector;
-                _resultSelector = resultSelector;
-                _comparer = comparer;
-            }
-
-            public IAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken)
-            {
-                cancellationToken.ThrowIfCancellationRequested(); // NB: [LDM-2018-11-28] Equivalent to async iterator behavior.
-
-                return new GroupJoinAsyncEnumeratorWithTask(
-                    _outer.GetAsyncEnumerator(cancellationToken),
-                    _inner,
-                    _outerKeySelector,
-                    _innerKeySelector,
-                    _resultSelector,
-                    _comparer,
-                    cancellationToken);
-            }
-
-            private sealed class GroupJoinAsyncEnumeratorWithTask : IAsyncEnumerator<TResult>
-            {
-                private readonly IEqualityComparer<TKey> _comparer;
-                private readonly IAsyncEnumerable<TInner> _inner;
-                private readonly Func<TInner, CancellationToken, ValueTask<TKey>> _innerKeySelector;
-                private readonly IAsyncEnumerator<TOuter> _outer;
-                private readonly Func<TOuter, CancellationToken, ValueTask<TKey>> _outerKeySelector;
-                private readonly Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>> _resultSelector;
-                private readonly CancellationToken _cancellationToken;
-
-                private Internal.LookupWithTask<TKey, TInner> _lookup;
-
-                public GroupJoinAsyncEnumeratorWithTask(
-                    IAsyncEnumerator<TOuter> outer,
-                    IAsyncEnumerable<TInner> inner,
-                    Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector,
-                    Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector,
-                    Func<TOuter, IAsyncEnumerable<TInner>, CancellationToken, ValueTask<TResult>> resultSelector,
-                    IEqualityComparer<TKey> comparer,
-                    CancellationToken cancellationToken)
-                {
-                    _outer = outer;
-                    _inner = inner;
-                    _outerKeySelector = outerKeySelector;
-                    _innerKeySelector = innerKeySelector;
-                    _resultSelector = resultSelector;
-                    _comparer = comparer;
-                    _cancellationToken = cancellationToken;
-                }
-
-                public async ValueTask<bool> MoveNextAsync()
-                {
-                    // nothing to do 
-                    if (!await _outer.MoveNextAsync().ConfigureAwait(false))
-                    {
-                        return false;
-                    }
-
-                    if (_lookup == null)
-                    {
-                        _lookup = await Internal.LookupWithTask<TKey, TInner>.CreateForJoinAsync(_inner, _innerKeySelector, _comparer, _cancellationToken).ConfigureAwait(false);
-                    }
-
-                    var item = _outer.Current;
-
-                    var outerKey = await _outerKeySelector(item, _cancellationToken).ConfigureAwait(false);
-                    var inner = _lookup[outerKey].ToAsyncEnumerable();
-
-                    Current = await _resultSelector(item, inner, _cancellationToken).ConfigureAwait(false);
-
-                    return true;
-                }
-
-                public TResult Current { get; private set; }
-
-                public ValueTask DisposeAsync() => _outer.DisposeAsync();
-            }
-        }
-#endif
 #endif
     }
 }

+ 0 - 85
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Intersect.cs

@@ -21,7 +21,6 @@ namespace System.Linq
             if (second == null)
                 throw Error.ArgumentNull(nameof(second));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -41,90 +40,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new IntersectAsyncIterator<TSource>(first, second, comparer);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class IntersectAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly IEqualityComparer<TSource> _comparer;
-            private readonly IAsyncEnumerable<TSource> _first;
-            private readonly IAsyncEnumerable<TSource> _second;
-
-            private IAsyncEnumerator<TSource> _firstEnumerator;
-            private Set<TSource> _set;
-
-            public IntersectAsyncIterator(IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
-            {
-                Debug.Assert(first != null);
-                Debug.Assert(second != null);
-
-                _first = first;
-                _second = second;
-                _comparer = comparer;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new IntersectAsyncIterator<TSource>(_first, _second, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_firstEnumerator != null)
-                {
-                    await _firstEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _firstEnumerator = null;
-                }
-
-                _set = null;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            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;
-            }
-        }
-#endif
     }
 }

+ 0 - 397
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Join.cs

@@ -27,7 +27,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -64,9 +63,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new JoinAsyncIterator<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
-#endif
         }
 
         internal static IAsyncEnumerable<TResult> JoinAwaitCore<TOuter, TInner, TKey, TResult>(this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, ValueTask<TResult>> resultSelector) =>
@@ -85,7 +81,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -122,9 +117,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new JoinAsyncIteratorWithTask<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -144,7 +136,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -181,395 +172,7 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new JoinAsyncIteratorWithTaskAndCancellation<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class JoinAsyncIterator<TOuter, TInner, TKey, TResult> : AsyncIterator<TResult>
-        {
-            private readonly IAsyncEnumerable<TOuter> _outer;
-            private readonly IAsyncEnumerable<TInner> _inner;
-            private readonly Func<TOuter, TKey> _outerKeySelector;
-            private readonly Func<TInner, TKey> _innerKeySelector;
-            private readonly Func<TOuter, TInner, TResult> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
-
-            private IAsyncEnumerator<TOuter> _outerEnumerator;
-
-            public JoinAsyncIterator(IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer)
-            {
-                Debug.Assert(outer != null);
-                Debug.Assert(inner != null);
-                Debug.Assert(outerKeySelector != null);
-                Debug.Assert(innerKeySelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _outer = outer;
-                _inner = inner;
-                _outerKeySelector = outerKeySelector;
-                _innerKeySelector = innerKeySelector;
-                _resultSelector = resultSelector;
-                _comparer = comparer;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new JoinAsyncIterator<TOuter, TInner, TKey, TResult>(_outer, _inner, _outerKeySelector, _innerKeySelector, _resultSelector, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_outerEnumerator != null)
-                {
-                    await _outerEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _outerEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            // State machine vars
-            private Internal.Lookup<TKey, TInner> _lookup;
-            private int _count;
-            private TInner[] _elements;
-            private int _index;
-            private TOuter _item;
-            private int _mode;
-
-            private const int State_If = 1;
-            private const int State_DoLoop = 2;
-            private const int State_For = 3;
-            private const int State_While = 4;
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _outerEnumerator = _outer.GetAsyncEnumerator(_cancellationToken);
-                        _mode = State_If;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_If:
-                                if (await _outerEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _lookup = await Internal.Lookup<TKey, TInner>.CreateForJoinAsync(_inner, _innerKeySelector, _comparer, _cancellationToken).ConfigureAwait(false);
-
-                                    if (_lookup.Count != 0)
-                                    {
-                                        _mode = State_DoLoop;
-                                        goto case State_DoLoop;
-                                    }
-                                }
-
-                                break;
-
-                            case State_DoLoop:
-                                _item = _outerEnumerator.Current;
-                                var g = _lookup.GetGrouping(_outerKeySelector(_item), create: false);
-                                if (g != null)
-                                {
-                                    _count = g._count;
-                                    _elements = g._elements;
-                                    _index = 0;
-                                    _mode = State_For;
-                                    goto case State_For;
-                                }
-
-                                // advance to while
-                                _mode = State_While;
-                                goto case State_While;
-
-                            case State_For:
-                                _current = _resultSelector(_item, _elements[_index]);
-                                _index++;
-                                if (_index == _count)
-                                {
-                                    _mode = State_While;
-                                }
-
-                                return true;
-
-                            case State_While:
-                                var hasNext = await _outerEnumerator.MoveNextAsync().ConfigureAwait(false);
-                                if (hasNext)
-                                {
-                                    goto case State_DoLoop;
-                                }
-
-                                break;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-
-        private sealed class JoinAsyncIteratorWithTask<TOuter, TInner, TKey, TResult> : AsyncIterator<TResult>
-        {
-            private readonly IAsyncEnumerable<TOuter> _outer;
-            private readonly IAsyncEnumerable<TInner> _inner;
-            private readonly Func<TOuter, ValueTask<TKey>> _outerKeySelector;
-            private readonly Func<TInner, ValueTask<TKey>> _innerKeySelector;
-            private readonly Func<TOuter, TInner, ValueTask<TResult>> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
-
-            private IAsyncEnumerator<TOuter> _outerEnumerator;
-
-            public JoinAsyncIteratorWithTask(IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, ValueTask<TKey>> outerKeySelector, Func<TInner, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
-            {
-                Debug.Assert(outer != null);
-                Debug.Assert(inner != null);
-                Debug.Assert(outerKeySelector != null);
-                Debug.Assert(innerKeySelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _outer = outer;
-                _inner = inner;
-                _outerKeySelector = outerKeySelector;
-                _innerKeySelector = innerKeySelector;
-                _resultSelector = resultSelector;
-                _comparer = comparer;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new JoinAsyncIteratorWithTask<TOuter, TInner, TKey, TResult>(_outer, _inner, _outerKeySelector, _innerKeySelector, _resultSelector, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_outerEnumerator != null)
-                {
-                    await _outerEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _outerEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            // State machine vars
-            private Internal.LookupWithTask<TKey, TInner> _lookup;
-            private int _count;
-            private TInner[] _elements;
-            private int _index;
-            private TOuter _item;
-            private int _mode;
-
-            private const int State_If = 1;
-            private const int State_DoLoop = 2;
-            private const int State_For = 3;
-            private const int State_While = 4;
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _outerEnumerator = _outer.GetAsyncEnumerator(_cancellationToken);
-                        _mode = State_If;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_If:
-                                if (await _outerEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _lookup = await Internal.LookupWithTask<TKey, TInner>.CreateForJoinAsync(_inner, _innerKeySelector, _comparer, _cancellationToken).ConfigureAwait(false);
-
-                                    if (_lookup.Count != 0)
-                                    {
-                                        _mode = State_DoLoop;
-                                        goto case State_DoLoop;
-                                    }
-                                }
-
-                                break;
-
-                            case State_DoLoop:
-                                _item = _outerEnumerator.Current;
-                                var g = _lookup.GetGrouping(await _outerKeySelector(_item).ConfigureAwait(false), create: false);
-                                if (g != null)
-                                {
-                                    _count = g._count;
-                                    _elements = g._elements;
-                                    _index = 0;
-                                    _mode = State_For;
-                                    goto case State_For;
-                                }
-
-                                // advance to while
-                                _mode = State_While;
-                                goto case State_While;
-
-                            case State_For:
-                                _current = await _resultSelector(_item, _elements[_index]).ConfigureAwait(false);
-                                _index++;
-                                if (_index == _count)
-                                {
-                                    _mode = State_While;
-                                }
-
-                                return true;
-
-                            case State_While:
-                                var hasNext = await _outerEnumerator.MoveNextAsync().ConfigureAwait(false);
-                                if (hasNext)
-                                {
-                                    goto case State_DoLoop;
-                                }
-
-                                break;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
         }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class JoinAsyncIteratorWithTaskAndCancellation<TOuter, TInner, TKey, TResult> : AsyncIterator<TResult>
-        {
-            private readonly IAsyncEnumerable<TOuter> _outer;
-            private readonly IAsyncEnumerable<TInner> _inner;
-            private readonly Func<TOuter, CancellationToken, ValueTask<TKey>> _outerKeySelector;
-            private readonly Func<TInner, CancellationToken, ValueTask<TKey>> _innerKeySelector;
-            private readonly Func<TOuter, TInner, CancellationToken, ValueTask<TResult>> _resultSelector;
-            private readonly IEqualityComparer<TKey> _comparer;
-
-            private IAsyncEnumerator<TOuter> _outerEnumerator;
-
-            public JoinAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector, Func<TOuter, TInner, CancellationToken, ValueTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
-            {
-                Debug.Assert(outer != null);
-                Debug.Assert(inner != null);
-                Debug.Assert(outerKeySelector != null);
-                Debug.Assert(innerKeySelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _outer = outer;
-                _inner = inner;
-                _outerKeySelector = outerKeySelector;
-                _innerKeySelector = innerKeySelector;
-                _resultSelector = resultSelector;
-                _comparer = comparer;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new JoinAsyncIteratorWithTaskAndCancellation<TOuter, TInner, TKey, TResult>(_outer, _inner, _outerKeySelector, _innerKeySelector, _resultSelector, _comparer);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_outerEnumerator != null)
-                {
-                    await _outerEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _outerEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            // State machine vars
-            private Internal.LookupWithTask<TKey, TInner> _lookup;
-            private int _count;
-            private TInner[] _elements;
-            private int _index;
-            private TOuter _item;
-            private int _mode;
-
-            private const int State_If = 1;
-            private const int State_DoLoop = 2;
-            private const int State_For = 3;
-            private const int State_While = 4;
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _outerEnumerator = _outer.GetAsyncEnumerator(_cancellationToken);
-                        _mode = State_If;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_If:
-                                if (await _outerEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _lookup = await Internal.LookupWithTask<TKey, TInner>.CreateForJoinAsync(_inner, _innerKeySelector, _comparer, _cancellationToken).ConfigureAwait(false);
-
-                                    if (_lookup.Count != 0)
-                                    {
-                                        _mode = State_DoLoop;
-                                        goto case State_DoLoop;
-                                    }
-                                }
-
-                                break;
-
-                            case State_DoLoop:
-                                _item = _outerEnumerator.Current;
-                                var g = _lookup.GetGrouping(await _outerKeySelector(_item, _cancellationToken).ConfigureAwait(false), create: false);
-                                if (g != null)
-                                {
-                                    _count = g._count;
-                                    _elements = g._elements;
-                                    _index = 0;
-                                    _mode = State_For;
-                                    goto case State_For;
-                                }
-
-                                // advance to while
-                                _mode = State_While;
-                                goto case State_While;
-
-                            case State_For:
-                                _current = await _resultSelector(_item, _elements[_index], _cancellationToken).ConfigureAwait(false);
-                                _index++;
-                                if (_index == _count)
-                                {
-                                    _mode = State_While;
-                                }
-
-                                return true;
-
-                            case State_While:
-                                var hasNext = await _outerEnumerator.MoveNextAsync().ConfigureAwait(false);
-                                if (hasNext)
-                                {
-                                    goto case State_DoLoop;
-                                }
-
-                                break;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
 #endif
     }
 }

+ 0 - 60
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OfType.cs

@@ -23,7 +23,6 @@ namespace System.Linq
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -36,65 +35,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new OfTypeAsyncIterator<TResult>(source);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class OfTypeAsyncIterator<TResult> : AsyncIterator<TResult>
-        {
-            private readonly IAsyncEnumerable<object> _source;
-            private IAsyncEnumerator<object> _enumerator;
-
-            public OfTypeAsyncIterator(IAsyncEnumerable<object> source)
-            {
-                _source = source;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new OfTypeAsyncIterator<TResult>(_source);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            if (item is TResult res)
-                            {
-                                _current = res;
-                                return true;
-                            }
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 210
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Select.cs

@@ -36,7 +36,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -53,9 +52,6 @@ namespace System.Linq
                     yield return selector(element, index);
                 }
             }
-#else
-            return new SelectEnumerableWithIndexAsyncIterator<TSource, TResult>(source, selector);
-#endif
         }
 
         internal static IAsyncEnumerable<TResult> SelectAwaitCore<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TResult>> selector)
@@ -103,7 +99,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -120,9 +115,6 @@ namespace System.Linq
                     yield return await selector(element, index).ConfigureAwait(false);
                 }
             }
-#else
-            return new SelectEnumerableWithIndexAsyncIteratorWithTask<TSource, TResult>(source, selector);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -133,7 +125,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -150,9 +141,6 @@ namespace System.Linq
                     yield return await selector(element, index, cancellationToken).ConfigureAwait(false);
                 }
             }
-#else
-            return new SelectEnumerableWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TResult>(source, selector);
-#endif
         }
 #endif
 
@@ -217,72 +205,6 @@ namespace System.Linq
             }
         }
 
-#if !USE_ASYNC_ITERATOR
-        private sealed class SelectEnumerableWithIndexAsyncIterator<TSource, TResult> : AsyncIterator<TResult>
-        {
-            private readonly Func<TSource, int, TResult> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public SelectEnumerableWithIndexAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, int, TResult> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectEnumerableWithIndexAsyncIterator<TSource, TResult>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            _current = _selector(item, _index);
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
-
         internal sealed class SelectIListIterator<TSource, TResult> : AsyncIterator<TResult>, IAsyncIListProvider<TResult>
         {
             private readonly Func<TSource, TResult> _selector;
@@ -523,138 +445,6 @@ namespace System.Linq
         }
 #endif
 
-#if !USE_ASYNC_ITERATOR
-        private sealed class SelectEnumerableWithIndexAsyncIteratorWithTask<TSource, TResult> : AsyncIterator<TResult>
-        {
-            private readonly Func<TSource, int, ValueTask<TResult>> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public SelectEnumerableWithIndexAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask<TResult>> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectEnumerableWithIndexAsyncIteratorWithTask<TSource, TResult>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            _current = await _selector(item, _index).ConfigureAwait(false);
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class SelectEnumerableWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TResult> : AsyncIterator<TResult>
-        {
-            private readonly Func<TSource, int, CancellationToken, ValueTask<TResult>> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public SelectEnumerableWithIndexAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, ValueTask<TResult>> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectEnumerableWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TResult>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            _current = await _selector(item, _index, _cancellationToken).ConfigureAwait(false);
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
-#endif
-
         // NB: LINQ to Objects implements IPartition<TResult> for this. However, it seems incorrect to do so in a trivial
         //     manner where e.g. TryGetLast simply indexes into the list without running the selector for the first n - 1
         //     elements in order to ensure side-effects. We should consider whether we want to follow this implementation

+ 0 - 950
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs

@@ -52,7 +52,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -74,9 +73,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyWithIndexAsyncIterator<TSource, TResult>(source, selector);
-#endif
         }
 
         internal static IAsyncEnumerable<TResult> SelectManyAwaitCore<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask<IAsyncEnumerable<TResult>>> selector)
@@ -86,7 +82,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -108,9 +103,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyWithIndexAsyncIteratorWithTask<TSource, TResult>(source, selector);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -121,7 +113,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -143,9 +134,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TResult>(source, selector);
-#endif
         }
 #endif
 
@@ -158,7 +146,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -173,9 +160,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyAsyncIterator<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
-#endif
         }
 
         internal static IAsyncEnumerable<TResult> SelectManyAwaitCore<TSource, TCollection, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<IAsyncEnumerable<TCollection>>> collectionSelector, Func<TSource, TCollection, ValueTask<TResult>> resultSelector)
@@ -187,7 +171,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -202,9 +185,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyAsyncIteratorWithTask<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -217,7 +197,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -232,9 +211,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyAsyncIteratorWithTaskAndCancellation<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
-#endif
         }
 #endif
 
@@ -247,7 +223,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -269,9 +244,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyWithIndexAsyncIterator<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
-#endif
         }
 
         internal static IAsyncEnumerable<TResult> SelectManyAwaitCore<TSource, TCollection, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask<IAsyncEnumerable<TCollection>>> collectionSelector, Func<TSource, TCollection, ValueTask<TResult>> resultSelector)
@@ -283,7 +255,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -305,9 +276,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyWithIndexAsyncIteratorWithTask<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -320,7 +288,6 @@ namespace System.Linq
             if (resultSelector == null)
                 throw Error.ArgumentNull(nameof(resultSelector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -342,9 +309,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SelectManyWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
-#endif
         }
 #endif
 
@@ -769,920 +733,6 @@ namespace System.Linq
                 return false;
             }
         }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class SelectManyAsyncIterator<TSource, TCollection, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, IAsyncEnumerable<TCollection>> _collectionSelector;
-            private readonly Func<TSource, TCollection, TResult> _resultSelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _currentSource;
-            private int _mode;
-            private IAsyncEnumerator<TCollection> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, IAsyncEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(collectionSelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _source = source;
-                _collectionSelector = collectionSelector;
-                _resultSelector = resultSelector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyAsyncIterator<TSource, TCollection, TResult>(_source, _collectionSelector, _resultSelector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                _currentSource = default;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _currentSource = _sourceEnumerator.Current;
-                                    var inner = _collectionSelector(_currentSource);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = _resultSelector(_currentSource, _resultEnumerator.Current);
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class SelectManyAsyncIteratorWithTask<TSource, TCollection, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, ValueTask<IAsyncEnumerable<TCollection>>> _collectionSelector;
-            private readonly Func<TSource, TCollection, ValueTask<TResult>> _resultSelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _currentSource;
-            private int _mode;
-            private IAsyncEnumerator<TCollection> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<IAsyncEnumerable<TCollection>>> collectionSelector, Func<TSource, TCollection, ValueTask<TResult>> resultSelector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(collectionSelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _source = source;
-                _collectionSelector = collectionSelector;
-                _resultSelector = resultSelector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyAsyncIteratorWithTask<TSource, TCollection, TResult>(_source, _collectionSelector, _resultSelector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                _currentSource = default;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _currentSource = _sourceEnumerator.Current;
-                                    var inner = await _collectionSelector(_currentSource).ConfigureAwait(false);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = await _resultSelector(_currentSource, _resultEnumerator.Current).ConfigureAwait(false);
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class SelectManyAsyncIteratorWithTaskAndCancellation<TSource, TCollection, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, CancellationToken, ValueTask<IAsyncEnumerable<TCollection>>> _collectionSelector;
-            private readonly Func<TSource, TCollection, CancellationToken, ValueTask<TResult>> _resultSelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _currentSource;
-            private int _mode;
-            private IAsyncEnumerator<TCollection> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<IAsyncEnumerable<TCollection>>> collectionSelector, Func<TSource, TCollection, CancellationToken, ValueTask<TResult>> resultSelector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(collectionSelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _source = source;
-                _collectionSelector = collectionSelector;
-                _resultSelector = resultSelector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyAsyncIteratorWithTaskAndCancellation<TSource, TCollection, TResult>(_source, _collectionSelector, _resultSelector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                _currentSource = default;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _currentSource = _sourceEnumerator.Current;
-                                    var inner = await _collectionSelector(_currentSource, _cancellationToken).ConfigureAwait(false);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = await _resultSelector(_currentSource, _resultEnumerator.Current, _cancellationToken).ConfigureAwait(false);
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
-
-        private sealed class SelectManyWithIndexAsyncIterator<TSource, TCollection, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, int, IAsyncEnumerable<TCollection>> _collectionSelector;
-            private readonly Func<TSource, TCollection, TResult> _resultSelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _currentSource;
-            private int _index;
-            private int _mode;
-            private IAsyncEnumerator<TCollection> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyWithIndexAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, int, IAsyncEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(collectionSelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _source = source;
-                _collectionSelector = collectionSelector;
-                _resultSelector = resultSelector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyWithIndexAsyncIterator<TSource, TCollection, TResult>(_source, _collectionSelector, _resultSelector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                _currentSource = default;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _currentSource = _sourceEnumerator.Current;
-
-                                    checked
-                                    {
-                                        _index++;
-                                    }
-
-                                    var inner = _collectionSelector(_currentSource, _index);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = _resultSelector(_currentSource, _resultEnumerator.Current);
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class SelectManyWithIndexAsyncIteratorWithTask<TSource, TCollection, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, int, ValueTask<IAsyncEnumerable<TCollection>>> _collectionSelector;
-            private readonly Func<TSource, TCollection, ValueTask<TResult>> _resultSelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _currentSource;
-            private int _index;
-            private int _mode;
-            private IAsyncEnumerator<TCollection> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyWithIndexAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask<IAsyncEnumerable<TCollection>>> collectionSelector, Func<TSource, TCollection, ValueTask<TResult>> resultSelector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(collectionSelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _source = source;
-                _collectionSelector = collectionSelector;
-                _resultSelector = resultSelector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyWithIndexAsyncIteratorWithTask<TSource, TCollection, TResult>(_source, _collectionSelector, _resultSelector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                _currentSource = default;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _currentSource = _sourceEnumerator.Current;
-
-                                    checked
-                                    {
-                                        _index++;
-                                    }
-
-                                    var inner = await _collectionSelector(_currentSource, _index).ConfigureAwait(false);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = await _resultSelector(_currentSource, _resultEnumerator.Current).ConfigureAwait(false);
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class SelectManyWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TCollection, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, int, CancellationToken, ValueTask<IAsyncEnumerable<TCollection>>> _collectionSelector;
-            private readonly Func<TSource, TCollection, CancellationToken, ValueTask<TResult>> _resultSelector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private TSource _currentSource;
-            private int _index;
-            private int _mode;
-            private IAsyncEnumerator<TCollection> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyWithIndexAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, ValueTask<IAsyncEnumerable<TCollection>>> collectionSelector, Func<TSource, TCollection, CancellationToken, ValueTask<TResult>> resultSelector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(collectionSelector != null);
-                Debug.Assert(resultSelector != null);
-
-                _source = source;
-                _collectionSelector = collectionSelector;
-                _resultSelector = resultSelector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TCollection, TResult>(_source, _collectionSelector, _resultSelector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                _currentSource = default;
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    _currentSource = _sourceEnumerator.Current;
-
-                                    checked
-                                    {
-                                        _index++;
-                                    }
-
-                                    var inner = await _collectionSelector(_currentSource, _index, _cancellationToken).ConfigureAwait(false);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = await _resultSelector(_currentSource, _resultEnumerator.Current, _cancellationToken).ConfigureAwait(false);
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
-
-        private sealed class SelectManyWithIndexAsyncIterator<TSource, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, int, IAsyncEnumerable<TResult>> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private int _index;
-            private int _mode;
-            private IAsyncEnumerator<TResult> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyWithIndexAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, int, IAsyncEnumerable<TResult>> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyWithIndexAsyncIterator<TSource, TResult>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    checked
-                                    {
-                                        _index++;
-                                    }
-
-                                    var inner = _selector(_sourceEnumerator.Current, _index);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = _resultEnumerator.Current;
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class SelectManyWithIndexAsyncIteratorWithTask<TSource, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, int, ValueTask<IAsyncEnumerable<TResult>>> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private int _index;
-            private int _mode;
-            private IAsyncEnumerator<TResult> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyWithIndexAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask<IAsyncEnumerable<TResult>>> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyWithIndexAsyncIteratorWithTask<TSource, TResult>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    checked
-                                    {
-                                        _index++;
-                                    }
-
-                                    var inner = await _selector(_sourceEnumerator.Current, _index).ConfigureAwait(false);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = _resultEnumerator.Current;
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class SelectManyWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TResult> : AsyncIterator<TResult>
-        {
-            private const int State_Source = 1;
-            private const int State_Result = 2;
-
-            private readonly Func<TSource, int, CancellationToken, ValueTask<IAsyncEnumerable<TResult>>> _selector;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private int _index;
-            private int _mode;
-            private IAsyncEnumerator<TResult> _resultEnumerator;
-            private IAsyncEnumerator<TSource> _sourceEnumerator;
-
-            public SelectManyWithIndexAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, ValueTask<IAsyncEnumerable<TResult>>> selector)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(selector != null);
-
-                _source = source;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new SelectManyWithIndexAsyncIteratorWithTaskAndCancellation<TSource, TResult>(_source, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_resultEnumerator != null)
-                {
-                    await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _resultEnumerator = null;
-                }
-
-                if (_sourceEnumerator != null)
-                {
-                    await _sourceEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _sourceEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _sourceEnumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _mode = State_Source;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        switch (_mode)
-                        {
-                            case State_Source:
-                                if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_resultEnumerator != null)
-                                    {
-                                        await _resultEnumerator.DisposeAsync().ConfigureAwait(false);
-                                    }
-
-                                    checked
-                                    {
-                                        _index++;
-                                    }
-
-                                    var inner = await _selector(_sourceEnumerator.Current, _index, _cancellationToken).ConfigureAwait(false);
-                                    _resultEnumerator = inner.GetAsyncEnumerator(_cancellationToken);
-
-                                    _mode = State_Result;
-                                    goto case State_Result;
-                                }
-                                break;
-
-                            case State_Result:
-                                if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    _current = _resultEnumerator.Current;
-                                    return true;
-                                }
-
-                                _mode = State_Source;
-                                goto case State_Source; // loop
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
 #endif
     }
 }

+ 0 - 74
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs

@@ -28,7 +28,6 @@ namespace System.Linq
                 count = 0;
             }
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -56,79 +55,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SkipLastAsyncIterator<TSource>(source, count);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class SkipLastAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly int _count;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private Queue<TSource> _queue;
-
-            public SkipLastAsyncIterator(IAsyncEnumerable<TSource> source, int count)
-            {
-                Debug.Assert(source != null);
-
-                _source = source;
-                _count = count;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new SkipLastAsyncIterator<TSource>(_source, _count);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                _queue = null; // release the memory
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _queue = new Queue<TSource>();
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            _queue.Enqueue(item);
-
-                            if (_queue.Count > _count)
-                            {
-                                _current = _queue.Dequeue();
-                                return true;
-                            }
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 510
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipWhile.cs

@@ -18,7 +18,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -43,9 +42,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SkipWhileAsyncIterator<TSource>(source, predicate);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> SkipWhile<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate)
@@ -55,7 +51,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -87,9 +82,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SkipWhileWithIndexAsyncIterator<TSource>(source, predicate);
-#endif
         }
 
         internal static IAsyncEnumerable<TSource> SkipWhileAwaitCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate)
@@ -99,7 +91,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -124,9 +115,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SkipWhileAsyncIteratorWithTask<TSource>(source, predicate);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -137,7 +125,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -162,9 +149,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SkipWhileAsyncIteratorWithTaskAndCancellation<TSource>(source, predicate);
-#endif
         }
 #endif
 
@@ -175,7 +159,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -207,9 +190,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SkipWhileWithIndexAsyncIteratorWithTask<TSource>(source, predicate);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -220,7 +200,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -252,496 +231,7 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new SkipWhileWithIndexAsyncIteratorWithTaskAndCancellation<TSource>(source, predicate);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class SkipWhileAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, bool> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private bool _doMoveNext;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public SkipWhileAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new SkipWhileAsyncIterator<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-
-                        // skip elements as requested
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var element = _enumerator.Current;
-                            if (!_predicate(element))
-                            {
-                                _doMoveNext = false;
-                                _state = AsyncIteratorState.Iterating;
-                                goto case AsyncIteratorState.Iterating;
-                            }
-                        }
-
-                        break;
-
-                    case AsyncIteratorState.Iterating:
-                        if (_doMoveNext && await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        if (!_doMoveNext)
-                        {
-                            _current = _enumerator.Current;
-                            _doMoveNext = true;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class SkipWhileWithIndexAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, bool> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private bool _doMoveNext;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public SkipWhileWithIndexAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new SkipWhileWithIndexAsyncIterator<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-
-                        // skip elements as requested
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var element = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (!_predicate(element, _index))
-                            {
-                                _doMoveNext = false;
-                                _state = AsyncIteratorState.Iterating;
-                                goto case AsyncIteratorState.Iterating;
-                            }
-                        }
-
-                        break;
-
-                    case AsyncIteratorState.Iterating:
-                        if (_doMoveNext && await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        if (!_doMoveNext)
-                        {
-                            _current = _enumerator.Current;
-                            _doMoveNext = true;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class SkipWhileAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private bool _doMoveNext;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public SkipWhileAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new SkipWhileAsyncIteratorWithTask<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-
-                        // skip elements as requested
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var element = _enumerator.Current;
-                            if (!await _predicate(element).ConfigureAwait(false))
-                            {
-                                _doMoveNext = false;
-                                _state = AsyncIteratorState.Iterating;
-                                goto case AsyncIteratorState.Iterating;
-                            }
-                        }
-
-                        break;
-
-                    case AsyncIteratorState.Iterating:
-                        if (_doMoveNext && await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        if (!_doMoveNext)
-                        {
-                            _current = _enumerator.Current;
-                            _doMoveNext = true;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
         }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class SkipWhileAsyncIteratorWithTaskAndCancellation<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, CancellationToken, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private bool _doMoveNext;
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public SkipWhileAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new SkipWhileAsyncIteratorWithTaskAndCancellation<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-
-                        // skip elements as requested
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var element = _enumerator.Current;
-                            if (!await _predicate(element, _cancellationToken).ConfigureAwait(false))
-                            {
-                                _doMoveNext = false;
-                                _state = AsyncIteratorState.Iterating;
-                                goto case AsyncIteratorState.Iterating;
-                            }
-                        }
-
-                        break;
-
-                    case AsyncIteratorState.Iterating:
-                        if (_doMoveNext && await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        if (!_doMoveNext)
-                        {
-                            _current = _enumerator.Current;
-                            _doMoveNext = true;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
-
-        private sealed class SkipWhileWithIndexAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private bool _doMoveNext;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public SkipWhileWithIndexAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new SkipWhileWithIndexAsyncIteratorWithTask<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-
-                        // skip elements as requested
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var element = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (!await _predicate(element, _index).ConfigureAwait(false))
-                            {
-                                _doMoveNext = false;
-                                _state = AsyncIteratorState.Iterating;
-                                goto case AsyncIteratorState.Iterating;
-                            }
-                        }
-
-                        break;
-
-                    case AsyncIteratorState.Iterating:
-                        if (_doMoveNext && await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        if (!_doMoveNext)
-                        {
-                            _current = _enumerator.Current;
-                            _doMoveNext = true;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class SkipWhileWithIndexAsyncIteratorWithTaskAndCancellation<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, CancellationToken, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private bool _doMoveNext;
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public SkipWhileWithIndexAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new SkipWhileWithIndexAsyncIteratorWithTaskAndCancellation<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-
-                        // skip elements as requested
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var element = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (!await _predicate(element, _index, _cancellationToken).ConfigureAwait(false))
-                            {
-                                _doMoveNext = false;
-                                _state = AsyncIteratorState.Iterating;
-                                goto case AsyncIteratorState.Iterating;
-                            }
-                        }
-
-                        break;
-
-                    case AsyncIteratorState.Iterating:
-                        if (_doMoveNext && await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _enumerator.Current;
-                            return true;
-                        }
-
-                        if (!_doMoveNext)
-                        {
-                            _current = _enumerator.Current;
-                            _doMoveNext = true;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
 #endif
     }
 }

+ 0 - 99
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/TakeLast.cs

@@ -21,7 +21,6 @@ namespace System.Linq
                 return Empty<TSource>();
             }
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -64,104 +63,6 @@ namespace System.Linq
                 }
                 while (queue.Count > 0);
             }
-#else
-            return new TakeLastAsyncIterator<TSource>(source, count);
-#endif
         }
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class TakeLastAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly int _count;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private bool _isDone;
-            private Queue<TSource> _queue;
-
-            public TakeLastAsyncIterator(IAsyncEnumerable<TSource> source, int count)
-            {
-                Debug.Assert(source != null);
-
-                _source = source;
-                _count = count;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new TakeLastAsyncIterator<TSource>(_source, _count);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                _queue = null; // release the memory
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _queue = new Queue<TSource>();
-                        _isDone = false;
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-
-                    case AsyncIteratorState.Iterating:
-                        while (true)
-                        {
-                            if (!_isDone)
-                            {
-                                if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                                {
-                                    if (_count > 0)
-                                    {
-                                        var item = _enumerator.Current;
-                                        if (_queue.Count >= _count)
-                                        {
-                                            _queue.Dequeue();
-                                        }
-                                        _queue.Enqueue(item);
-                                    }
-                                }
-                                else
-                                {
-                                    _isDone = true;
-                                    // Dispose early here as we can
-                                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                                    _enumerator = null;
-                                }
-
-                                continue; // loop until queue is drained
-                            }
-
-                            if (_queue.Count > 0)
-                            {
-                                _current = _queue.Dequeue();
-                                return true;
-                            }
-
-                            break; // while
-                        }
-
-                        break; // case
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
     }
 }

+ 0 - 430
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/TakeWhile.cs

@@ -18,7 +18,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -33,9 +32,6 @@ namespace System.Linq
                     yield return element;
                 }
             }
-#else
-            return new TakeWhileAsyncIterator<TSource>(source, predicate);
-#endif
         }
 
         public static IAsyncEnumerable<TSource> TakeWhile<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate)
@@ -45,7 +41,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -67,9 +62,6 @@ namespace System.Linq
                     yield return element;
                 }
             }
-#else
-            return new TakeWhileWithIndexAsyncIterator<TSource>(source, predicate);
-#endif
         }
 
         internal static IAsyncEnumerable<TSource> TakeWhileAwaitCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate)
@@ -79,7 +71,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -94,9 +85,6 @@ namespace System.Linq
                     yield return element;
                 }
             }
-#else
-            return new TakeWhileAsyncIteratorWithTask<TSource>(source, predicate);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -107,7 +95,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -122,9 +109,6 @@ namespace System.Linq
                     yield return element;
                 }
             }
-#else
-            return new TakeWhileAsyncIteratorWithTaskAndCancellation<TSource>(source, predicate);
-#endif
         }
 #endif
 
@@ -135,7 +119,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -157,9 +140,6 @@ namespace System.Linq
                     yield return element;
                 }
             }
-#else
-            return new TakeWhileWithIndexAsyncIteratorWithTask<TSource>(source, predicate);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -170,7 +150,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -192,416 +171,7 @@ namespace System.Linq
                     yield return element;
                 }
             }
-#else
-            return new TakeWhileWithIndexAsyncIteratorWithTaskAndCancellation<TSource>(source, predicate);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class TakeWhileAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, bool> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public TakeWhileAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new TakeWhileAsyncIterator<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            if (!_predicate(item))
-                            {
-                                break;
-                            }
-
-                            _current = item;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class TakeWhileWithIndexAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, bool> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public TakeWhileWithIndexAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new TakeWhileWithIndexAsyncIterator<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (!_predicate(item, _index))
-                            {
-                                break;
-                            }
-
-                            _current = item;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-        private sealed class TakeWhileAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public TakeWhileAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new TakeWhileAsyncIteratorWithTask<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            if (!await _predicate(item).ConfigureAwait(false))
-                            {
-                                break;
-                            }
-
-                            _current = item;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
         }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class TakeWhileAsyncIteratorWithTaskAndCancellation<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, CancellationToken, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-
-            public TakeWhileAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new TakeWhileAsyncIteratorWithTaskAndCancellation<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-                            if (!await _predicate(item, _cancellationToken).ConfigureAwait(false))
-                            {
-                                break;
-                            }
-
-                            _current = item;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
-
-        private sealed class TakeWhileWithIndexAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public TakeWhileWithIndexAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new TakeWhileWithIndexAsyncIteratorWithTask<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (!await _predicate(item, _index).ConfigureAwait(false))
-                            {
-                                break;
-                            }
-
-                            _current = item;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class TakeWhileWithIndexAsyncIteratorWithTaskAndCancellation<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, CancellationToken, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public TakeWhileWithIndexAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(predicate != null);
-                Debug.Assert(source != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new TakeWhileWithIndexAsyncIteratorWithTaskAndCancellation<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (!await _predicate(item, _index, _cancellationToken).ConfigureAwait(false))
-                            {
-                                break;
-                            }
-
-                            _current = item;
-                            return true;
-                        }
-
-                        break;
-                }
-
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
-            }
-        }
-#endif
 #endif
     }
 }

+ 0 - 222
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs

@@ -34,7 +34,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -54,9 +53,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new WhereEnumerableWithIndexAsyncIterator<TSource>(source, predicate);
-#endif
         }
 
         internal static IAsyncEnumerable<TSource> WhereAwaitCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate)
@@ -100,7 +96,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -120,9 +115,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new WhereEnumerableWithIndexAsyncIteratorWithTask<TSource>(source, predicate);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -133,7 +125,6 @@ namespace System.Linq
             if (predicate == null)
                 throw Error.ArgumentNull(nameof(predicate));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
@@ -153,9 +144,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new WhereEnumerableWithIndexAsyncIteratorWithTaskAndCancellation<TSource>(source, predicate);
-#endif
         }
 #endif
 
@@ -228,76 +216,6 @@ namespace System.Linq
             }
         }
 
-#if !USE_ASYNC_ITERATOR
-        private sealed class WhereEnumerableWithIndexAsyncIterator<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, bool> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public WhereEnumerableWithIndexAsyncIterator(IAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(predicate != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new WhereEnumerableWithIndexAsyncIterator<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (_predicate(item, _index))
-                            {
-                                _current = item;
-                                return true;
-                            }
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
-
         internal sealed class WhereEnumerableAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
         {
             private readonly Func<TSource, ValueTask<bool>> _predicate;
@@ -428,146 +346,6 @@ namespace System.Linq
         }
 #endif
 
-#if !USE_ASYNC_ITERATOR
-        private sealed class WhereEnumerableWithIndexAsyncIteratorWithTask<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public WhereEnumerableWithIndexAsyncIteratorWithTask(IAsyncEnumerable<TSource> source, Func<TSource, int, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(predicate != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new WhereEnumerableWithIndexAsyncIteratorWithTask<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (await _predicate(item, _index).ConfigureAwait(false))
-                            {
-                                _current = item;
-                                return true;
-                            }
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class WhereEnumerableWithIndexAsyncIteratorWithTaskAndCancellation<TSource> : AsyncIterator<TSource>
-        {
-            private readonly Func<TSource, int, CancellationToken, ValueTask<bool>> _predicate;
-            private readonly IAsyncEnumerable<TSource> _source;
-
-            private IAsyncEnumerator<TSource> _enumerator;
-            private int _index;
-
-            public WhereEnumerableWithIndexAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, ValueTask<bool>> predicate)
-            {
-                Debug.Assert(source != null);
-                Debug.Assert(predicate != null);
-
-                _source = source;
-                _predicate = predicate;
-            }
-
-            public override AsyncIteratorBase<TSource> Clone()
-            {
-                return new WhereEnumerableWithIndexAsyncIteratorWithTaskAndCancellation<TSource>(_source, _predicate);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_enumerator != null)
-                {
-                    await _enumerator.DisposeAsync().ConfigureAwait(false);
-                    _enumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _enumerator = _source.GetAsyncEnumerator(_cancellationToken);
-                        _index = -1;
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        while (await _enumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            var item = _enumerator.Current;
-
-                            checked
-                            {
-                                _index++;
-                            }
-
-                            if (await _predicate(item, _index, _cancellationToken).ConfigureAwait(false))
-                            {
-                                _current = item;
-                                return true;
-                            }
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
-#endif
-
         private sealed class WhereSelectEnumerableAsyncIterator<TSource, TResult> : AsyncIterator<TResult>
         {
             private readonly Func<TSource, bool> _predicate;

+ 0 - 236
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Zip.cs

@@ -19,7 +19,6 @@ namespace System.Linq
             if (second == null)
                 throw Error.ArgumentNull(nameof(second));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<(TFirst, TSecond)> Core(CancellationToken cancellationToken)
@@ -35,9 +34,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ZipAsyncIterator<TFirst, TSecond, (TFirst, TSecond)>(first, second, (first, second) => (first, second));
-#endif
         }
 #endif
 
@@ -50,7 +46,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -66,9 +61,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ZipAsyncIterator<TFirst, TSecond, TResult>(first, second, selector);
-#endif
         }
 
         internal static IAsyncEnumerable<TResult> ZipAwaitCore<TFirst, TSecond, TResult>(this IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, ValueTask<TResult>> selector)
@@ -80,7 +72,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -96,9 +87,6 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ZipAsyncIteratorWithTask<TFirst, TSecond, TResult>(first, second, selector);
-#endif
         }
 
 #if !NO_DEEP_CANCELLATION
@@ -111,7 +99,6 @@ namespace System.Linq
             if (selector == null)
                 throw Error.ArgumentNull(nameof(selector));
 
-#if USE_ASYNC_ITERATOR
             return Create(Core);
 
             async IAsyncEnumerator<TResult> Core(CancellationToken cancellationToken)
@@ -127,230 +114,7 @@ namespace System.Linq
                     }
                 }
             }
-#else
-            return new ZipAsyncIteratorWithTaskAndCancellation<TFirst, TSecond, TResult>(first, second, selector);
-#endif
-        }
-#endif
-
-#if !USE_ASYNC_ITERATOR
-        private sealed class ZipAsyncIterator<TFirst, TSecond, TResult> : AsyncIterator<TResult>
-        {
-            private readonly IAsyncEnumerable<TFirst> _first;
-            private readonly IAsyncEnumerable<TSecond> _second;
-            private readonly Func<TFirst, TSecond, TResult> _selector;
-
-            private IAsyncEnumerator<TFirst> _firstEnumerator;
-            private IAsyncEnumerator<TSecond> _secondEnumerator;
-
-            public ZipAsyncIterator(IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> selector)
-            {
-                Debug.Assert(first != null);
-                Debug.Assert(second != null);
-                Debug.Assert(selector != null);
-
-                _first = first;
-                _second = second;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new ZipAsyncIterator<TFirst, TSecond, TResult>(_first, _second, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_secondEnumerator != null)
-                {
-                    await _secondEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _secondEnumerator = null;
-                }
-
-                if (_firstEnumerator != null)
-                {
-                    await _firstEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _firstEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                // REVIEW: Earlier versions of this operator performed concurrent MoveNextAsync calls, which isn't a great default and
-                //         results in an unexpected source of concurrency. However, a concurrent Zip may be a worthy addition to the
-                //         API or System.Interactive.Async as a complementary implementation besides the conservative default.
-
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _firstEnumerator = _first.GetAsyncEnumerator(_cancellationToken);
-                        _secondEnumerator = _second.GetAsyncEnumerator(_cancellationToken);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _firstEnumerator.MoveNextAsync().ConfigureAwait(false) && await _secondEnumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = _selector(_firstEnumerator.Current, _secondEnumerator.Current);
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
         }
-
-        private sealed class ZipAsyncIteratorWithTask<TFirst, TSecond, TResult> : AsyncIterator<TResult>
-        {
-            private readonly IAsyncEnumerable<TFirst> _first;
-            private readonly IAsyncEnumerable<TSecond> _second;
-            private readonly Func<TFirst, TSecond, ValueTask<TResult>> _selector;
-
-            private IAsyncEnumerator<TFirst> _firstEnumerator;
-            private IAsyncEnumerator<TSecond> _secondEnumerator;
-
-            public ZipAsyncIteratorWithTask(IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, ValueTask<TResult>> selector)
-            {
-                Debug.Assert(first != null);
-                Debug.Assert(second != null);
-                Debug.Assert(selector != null);
-
-                _first = first;
-                _second = second;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new ZipAsyncIteratorWithTask<TFirst, TSecond, TResult>(_first, _second, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_secondEnumerator != null)
-                {
-                    await _secondEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _secondEnumerator = null;
-                }
-
-                if (_firstEnumerator != null)
-                {
-                    await _firstEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _firstEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                // REVIEW: Earlier versions of this operator performed concurrent MoveNextAsync calls, which isn't a great default and
-                //         results in an unexpected source of concurrency. However, a concurrent Zip may be a worthy addition to the
-                //         API or System.Interactive.Async as a complementary implementation besides the conservative default.
-
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _firstEnumerator = _first.GetAsyncEnumerator(_cancellationToken);
-                        _secondEnumerator = _second.GetAsyncEnumerator(_cancellationToken);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _firstEnumerator.MoveNextAsync().ConfigureAwait(false) && await _secondEnumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = await _selector(_firstEnumerator.Current, _secondEnumerator.Current).ConfigureAwait(false);
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-
-#if !NO_DEEP_CANCELLATION
-        private sealed class ZipAsyncIteratorWithTaskAndCancellation<TFirst, TSecond, TResult> : AsyncIterator<TResult>
-        {
-            private readonly IAsyncEnumerable<TFirst> _first;
-            private readonly IAsyncEnumerable<TSecond> _second;
-            private readonly Func<TFirst, TSecond, CancellationToken, ValueTask<TResult>> _selector;
-
-            private IAsyncEnumerator<TFirst> _firstEnumerator;
-            private IAsyncEnumerator<TSecond> _secondEnumerator;
-
-            public ZipAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable<TFirst> first, IAsyncEnumerable<TSecond> second, Func<TFirst, TSecond, CancellationToken, ValueTask<TResult>> selector)
-            {
-                Debug.Assert(first != null);
-                Debug.Assert(second != null);
-                Debug.Assert(selector != null);
-
-                _first = first;
-                _second = second;
-                _selector = selector;
-            }
-
-            public override AsyncIteratorBase<TResult> Clone()
-            {
-                return new ZipAsyncIteratorWithTaskAndCancellation<TFirst, TSecond, TResult>(_first, _second, _selector);
-            }
-
-            public override async ValueTask DisposeAsync()
-            {
-                if (_secondEnumerator != null)
-                {
-                    await _secondEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _secondEnumerator = null;
-                }
-
-                if (_firstEnumerator != null)
-                {
-                    await _firstEnumerator.DisposeAsync().ConfigureAwait(false);
-                    _firstEnumerator = null;
-                }
-
-                await base.DisposeAsync().ConfigureAwait(false);
-            }
-
-            protected override async ValueTask<bool> MoveNextCore()
-            {
-                // REVIEW: Earlier versions of this operator performed concurrent MoveNextAsync calls, which isn't a great default and
-                //         results in an unexpected source of concurrency. However, a concurrent Zip may be a worthy addition to the
-                //         API or System.Interactive.Async as a complementary implementation besides the conservative default.
-
-                switch (_state)
-                {
-                    case AsyncIteratorState.Allocated:
-                        _firstEnumerator = _first.GetAsyncEnumerator(_cancellationToken);
-                        _secondEnumerator = _second.GetAsyncEnumerator(_cancellationToken);
-
-                        _state = AsyncIteratorState.Iterating;
-                        goto case AsyncIteratorState.Iterating;
-
-                    case AsyncIteratorState.Iterating:
-                        if (await _firstEnumerator.MoveNextAsync().ConfigureAwait(false) && await _secondEnumerator.MoveNextAsync().ConfigureAwait(false))
-                        {
-                            _current = await _selector(_firstEnumerator.Current, _secondEnumerator.Current, _cancellationToken).ConfigureAwait(false);
-                            return true;
-                        }
-
-                        await DisposeAsync().ConfigureAwait(false);
-                        break;
-                }
-
-                return false;
-            }
-        }
-#endif
 #endif
     }
 }