private static async Task _enumerate(AsyncEnumerator <TSource> .Yield yield, WhereWithIndexContext <TSource> context) { using (var enumerator = await context.Source.GetAsyncEnumeratorAsync(yield.CancellationToken).ConfigureAwait(false)) { long index = 0; while (await enumerator.MoveNextAsync(yield.CancellationToken).ConfigureAwait(false)) { if (context.Predicate(enumerator.Current, index)) { await yield.ReturnAsync(enumerator.Current).ConfigureAwait(false); } index++; } } }
private static async Task _enumerate(AsyncEnumerator <TSource> .Yield yield, WhereWithIndexContext <TSource> context) { try { long index = 0; while (await context.Source.MoveNextAsync(yield.CancellationToken).ConfigureAwait(false)) { if (context.Predicate(context.Source.Current, index)) { await yield.ReturnAsync(context.Source.Current).ConfigureAwait(false); } index++; } } finally { if (context.DisposeSource) { context.Source.Dispose(); } } }