Closed
Description
When a benchmark returns a ValueTask
, it is simply called with .GetAwaiter().GetResult()
.
This is illegal ValueTask
usage: you must not call GetResult()
until the task has been completed.
IValueTaskSource
-backed tasks do not need to support blocking on GetResult()
. The in-box ManualResetValueTaskSourceCore
does not support blocking GetResult()
. Nor does the DOTNET_SYSTEM_THREADING_POOLASYNCVALUETASKS
feature in .NET 5.
Instead, the ValueTask
should be converted to a Task
first:
static void BlockForResult(ValueTask task)
{
if (task.IsCompleted)
task.GetAwaiter().GetResult();
else
task.AsTask().GetAwaiter().GetResult();
}
(This will be unfortunate for the memory diagnoser, as a bogus Task
will show up, but the alternative is to just crash...)