Files
coverlet/test/coverlet.core.tests/Samples/Instrumentation.AsyncIterator.cs
Alex Thornton b5923ca216 Coverage for "await foreach" loops and compiler-generated async iterators (issue #1104) (#1107)
Coverage for "await foreach" loops and compiler-generated async iterators (issue #1104) (#1107)
2021-03-06 23:00:48 +01:00

35 lines
767 B
C#

// Remember to use full name because adding new using directives change line numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Coverlet.Core.Samples.Tests
{
public class AsyncIterator
{
async public Task<int> Issue1104_Repro()
{
int sum = 0;
await foreach (int result in CreateSequenceAsync())
{
sum += result;
}
return sum;
}
async private IAsyncEnumerable<int> CreateSequenceAsync()
{
for (int i = 0; i < 100; ++i)
{
await Task.CompletedTask;
yield return i;
}
}
}
}