AsyncEnumerable icon indicating copy to clipboard operation
AsyncEnumerable copied to clipboard

Using of GetAwaiter().GetResult() from ValueTask<T> in EnumeratorAdapter

Open Gordory opened this issue 4 years ago • 0 comments

Hi there!

For some reason I used ToEnumerable() extension to iterate IAsyncEnumerable synchronously. And for sure I got the exception from this line of code.

Documentation tells us that this is not valid call for ValueTask: "The following operations should never be performed on a ValueTask<TResult> instance: ... Using .Result or .GetAwaiter().GetResult() when the operation hasn't yet completed, or using them multiple times".

I know, that I shouldn't use this extension, but I think this still should work correctly.

Also found some more usages of GetAwaiter().GetResult() from ValueTask in your code:

  • This Dispose code in AsyncEnumerator, which can be a bigger problem than I found.
  • This extension method AsyncEnumerableAdapterExtensions.MoveNext leaved for backward compatibility.

Gordory avatar Jan 19 '21 09:01 Gordory