yield.Break() leads to TaskCanceledException
Denis535 opened this issue · 2 comments
Denis535 commented
Look at next code:
var e = GetItems().GetAsyncEnumeratorAsync().Result;
e.MoveNextAsync().Wait();
e.MoveNextAsync().Wait(); // this line throws: TaskCanceledException: A task was canceled.
private static IAsyncEnumerable<int> GetItems() {
return new AsyncEnumerable<int>( GetItems );
}
private static async Task GetItems(AsyncEnumerator<int>.Yield yield) {
await Task.Delay( 1 );
await yield.ReturnAsync( 0 );
yield.Break(); // break
await Task.Delay( 1 );
await yield.ReturnAsync( 1 );
}
IEnumerable.MoveNext() returns just false when enumerator is ended with yeild. So I decided it's bug or strange behavior.
Denis535 commented
IAsyncEnumerable.ForEachAsync( ... ).Wait() also leads to exception. And it's real problem.
kind-serge commented
@deni35, yes, it's a bug indeed. The problem has been fixed and the new version 2.2.2 is available here:
https://www.nuget.org/packages/AsyncEnumerator/2.2.2