Skip to content

Add async support to System.Lazy #27510

@GSPP

Description

@GSPP

Lazy is a very useful class. With async code becoming more and more common we should make Lazy async aware. Doing that requires the following changes:

  1. Make the constructor accept Task-returning factory delegates.
  2. Add an async accessor method: Task<T> GetValueAsync()

If the synchronous T Value { get; } property is used then simply block on the task.

Is ValueTask appropriate to use here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-needs-workAPI needs work before it is approved, it is NOT ready for implementationarea-System.Runtime

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions