public struct AsyncValueTaskMethodBuilder<TResult>
{
/// <summary>The <see cref="AsyncTaskMethodBuilder{TResult}"/> to which most operations are delegated.</summary>
- private AsyncTaskMethodBuilder<TResult> _methodBuilder;
+ private AsyncTaskMethodBuilder<TResult> _methodBuilder; // mutable struct; do not make it readonly
/// <summary>The result for this builder, if it's completed before any awaits occur.</summary>
private TResult _result;
/// <summary>true if <see cref="_result"/> contains the synchronous result for the async method; otherwise, false.</summary>
public struct ConfiguredValueTaskAwaiter : ICriticalNotifyCompletion
{
/// <summary>The value being awaited.</summary>
- private readonly ValueTask<TResult> _value;
+ private ValueTask<TResult> _value; // Methods are called on this; avoid making it readonly so as to avoid unnecessary copies
/// <summary>The value to pass to ConfigureAwait.</summary>
private readonly bool _continueOnCapturedContext;
public struct ValueTaskAwaiter<TResult> : ICriticalNotifyCompletion
{
/// <summary>The value being awaited.</summary>
- private readonly ValueTask<TResult> _value;
+ private ValueTask<TResult> _value; // Methods are called on this; avoid making it readonly so as to avoid unnecessary copies
/// <summary>Initializes the awaiter.</summary>
/// <param name="value">The value to be awaited.</param>
public bool IsCompleted => _task == null || _task.IsCompleted;
/// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a successfully completed operation.</summary>
- public bool IsCompletedSuccessfully => _task == null || _task.Status == TaskStatus.RanToCompletion;
+ public bool IsCompletedSuccessfully => _task == null || _task.IsCompletedSuccessfully;
/// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a failed operation.</summary>
public bool IsFaulted => _task != null && _task.IsFaulted;
/// true to attempt to marshal the continuation back to the captured context; otherwise, false.
/// </param>
public ConfiguredValueTaskAwaitable<TResult> ConfigureAwait(bool continueOnCapturedContext) =>
- new ConfiguredValueTaskAwaitable<TResult>(this, continueOnCapturedContext: continueOnCapturedContext);
+ new ConfiguredValueTaskAwaitable<TResult>(this, continueOnCapturedContext);
/// <summary>Gets a string-representation of this <see cref="ValueTask{TResult}"/>.</summary>
public override string ToString()
{
if (_task != null)
{
- return _task.Status == TaskStatus.RanToCompletion && _task.Result != null ?
+ return _task.IsCompletedSuccessfully && _task.Result != null ?
_task.Result.ToString() :
string.Empty;
}
}
}
- // TODO: Remove CreateAsyncMethodBuilder once the C# compiler relies on the AsyncBuilder attribute.
+ // TODO https://github.com/dotnet/corefx/issues/22171:
+ // Remove CreateAsyncMethodBuilder once the C# compiler relies on the AsyncBuilder attribute.
/// <summary>Creates a method builder for use with an async method.</summary>
/// <returns>The created builder.</returns>