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:
- Make the constructor accept
Task-returning factory delegates.
- 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?
Lazyis a very useful class. With async code becoming more and more common we should makeLazyasync aware. Doing that requires the following changes:Task-returning factory delegates.Task<T> GetValueAsync()If the synchronous
T Value { get; }property is used then simply block on the task.Is
ValueTaskappropriate to use here?