diff options
-rw-r--r-- | src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs b/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs index 6b98a5f100..5edd8501b0 100644 --- a/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs +++ b/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs @@ -113,7 +113,12 @@ namespace System.Threading.Tasks // Return the task if we were constructed from one, otherwise manufacture one. We don't // cache the generated task into _task as it would end up changing both equality comparison // and the hash code we generate in GetHashCode. - _task ?? AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result); + _task ?? +#if netstandard + Task.FromResult(_result); +#else + AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result); +#endif internal Task<TResult> AsTaskExpectNonNull() => // Return the task if we were constructed from one, otherwise manufacture one. @@ -122,13 +127,24 @@ namespace System.Threading.Tasks _task ?? GetTaskForResultNoInlining(); [MethodImpl(MethodImplOptions.NoInlining)] - private Task<TResult> GetTaskForResultNoInlining() => AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result); + private Task<TResult> GetTaskForResultNoInlining() => +#if netstandard + Task.FromResult(_result); +#else + AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result); +#endif /// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a completed operation.</summary> 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.IsCompletedSuccessfully; + public bool IsCompletedSuccessfully => + _task == null || +#if netstandard + _task.Status == TaskStatus.RanToCompletion; +#else + _task.IsCompletedSuccessfully; +#endif /// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a failed operation.</summary> public bool IsFaulted => _task != null && _task.IsFaulted; @@ -152,18 +168,16 @@ namespace System.Threading.Tasks /// <summary>Gets a string-representation of this <see cref="ValueTask{TResult}"/>.</summary> public override string ToString() { - if (_task != null) + if (IsCompletedSuccessfully) { - return _task.IsCompletedSuccessfully && _task.Result != null ? - _task.Result.ToString() : - string.Empty; - } - else - { - return _result != null ? - _result.ToString() : - string.Empty; + TResult result = Result; + if (result != null) + { + return result.ToString(); + } } + + return string.Empty; } } } |