Class AsyncLazy<T>
Defines a provider for lazy asynchronous initialization of a value.
public class AsyncLazy<T>
Type Parameters
TThe type of object that is being lazily initialized.
- Inheritance
-
AsyncLazy<T>
- Inherited Members
- Extension Methods
Constructors
AsyncLazy(Func<Task<T>>)
Initializes a new instance of the AsyncLazy<T> class with the specified asynchronous value factory.
public AsyncLazy(Func<Task<T>> valueFactory)
Parameters
valueFactoryFunc<Task<T>>The asynchronous delegate that is invoked to produce the lazily initialized value when it is needed.
AsyncLazy(Func<Task<T>>, bool)
Initializes a new instance of the AsyncLazy<T> class with the specified asynchronous value factory and thread safety mode.
public AsyncLazy(Func<Task<T>> valueFactory, bool isThreadSafe)
Parameters
valueFactoryFunc<Task<T>>The asynchronous delegate that is invoked to produce the lazily initialized value when it is needed.
isThreadSafeboolA value indicating whether the AsyncLazy<T> instance should be usable concurrently by multiple threads.
Properties
IsValueCreated
Gets a value indicating whether a value has been created.
public bool IsValueCreated { get; }
Property Value
Methods
GetAwaiter()
Gets the lazily initialized value as an awaitable task.
public TaskAwaiter<T> GetAwaiter()
Returns
- TaskAwaiter<T>
An awaitable task that returns the lazily initialized value.
GetValueAsync()
Gets the lazily initialized value as a task.
public Task<T> GetValueAsync()
Returns
- Task<T>
A task that returns the lazily initialized value.