-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-System.Threading.Tasks
Milestone
Description
It's extremely common both in the framework itself and applications built on top of the framework to statically cache your own versions of Task with common results retrieved via Task.FromResult, similar to:
/// <summary>
/// Provides sentinel Tasks that represent commonly returned values.
/// </summary>
internal class TaskResult
{
/// <summary>
/// Represents a Task that's completed successfully with the result of <see langword="false"/>.
/// </summary>
public static readonly Task<bool> False = Task.FromResult(false);
/// <summary>
/// Represents a Task that's completed successfully with the result of <see langword="true"/>.
/// </summary>
public static readonly Task<bool> True = Task.FromResult(true);
}Just a few examples in 5 minutes of searching, are:
AsyncTaskCache in mscorlib
ADP in System.Data
AsyncHelper in System.Xml
TplExtensions in Microsoft.VisualStudio.Threading
TaskResult in ProjectSystem
Similar to what it did with Task.CompletedTask, the BCL should just provide these already cached values for common values, including true, false, empty string ("") and null.
jnm2, jp2masa, slang25, Daniel-Svensson, markusschaber and 1 more
Metadata
Metadata
Assignees
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-System.Threading.Tasks