コード例 #1
0
            private static async Task _enumerate(AsyncEnumerator <TResult> .Yield yield, SelectWithIndexContext <TSource, TResult> context)
            {
                using (var enumerator = await context.Source.GetAsyncEnumeratorAsync(yield.CancellationToken).ConfigureAwait(false))
                {
                    long index = 0;
                    while (await enumerator.MoveNextAsync(yield.CancellationToken).ConfigureAwait(false))
                    {
                        await yield.ReturnAsync(context.Selector(enumerator.Current, index)).ConfigureAwait(false);

                        index++;
                    }
                }
            }
コード例 #2
0
            private static async Task _enumerate(AsyncEnumerator <TResult> .Yield yield, SelectWithIndexContext <TSource, TResult> context)
            {
                try
                {
                    long index = 0;
                    while (await context.Source.MoveNextAsync(yield.CancellationToken).ConfigureAwait(false))
                    {
                        await yield.ReturnAsync(context.Selector(context.Source.Current, index)).ConfigureAwait(false);

                        index++;
                    }
                }
                finally
                {
                    if (context.DisposeSource)
                    {
                        context.Source.Dispose();
                    }
                }
            }