Class AsyncLazy<T>
Provides support for asynchronous lazy initialization.
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncLazy<T> : object
Type Parameters
Name | Description |
---|---|
T | The type of object that is being asynchronously initialized. |
Constructors
| Improve this Doc View SourceAsyncLazy(T)
Initializes a new instance of lazy value which is already computed.
Declaration
public AsyncLazy(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | Already computed value. |
AsyncLazy(Func<Task<T>>, Boolean)
Initializes a new instance of lazy value.
Declaration
public AsyncLazy(Func<Task<T>> valueFactory, bool resettable = false)
Parameters
Type | Name | Description |
---|---|---|
Func<Task<T>> | valueFactory | The function used to compute actual value. |
Boolean | resettable | true if previously computed value can be removed and computation executed again when it will be requested; false if value can be computed exactly once. |
AsyncLazy(ValueFunc<Task<T>>, Boolean)
Initializes a new instance of lazy value.
Declaration
public AsyncLazy(ValueFunc<Task<T>> valueFactory, bool resettable = false)
Parameters
Type | Name | Description |
---|---|---|
ValueFunc<Task<T>> | valueFactory | The function used to compute actual value. |
Boolean | resettable | true if previously computed value can be removed and computation executed again when it will be requested; false if value can be computed exactly once. |
Properties
| Improve this Doc View SourceIsValueCreated
Gets a value that indicates whether a value has been computed.
Declaration
public bool IsValueCreated { get; }
Property Value
Type | Description |
---|---|
Boolean |
Task
Gets task representing asynchronous computation of lazy value.
Declaration
public Task<T> Task { get; }
Property Value
Type | Description |
---|---|
Task<T> |
Value
Gets value if it is already computed.
Declaration
public Result<T>? Value { get; }
Property Value
Type | Description |
---|---|
Nullable<Result<T>> |
Methods
| Improve this Doc View SourceConfigureAwait(Boolean)
Configures an awaiter used to await asynchronous lazy initialization.
Declaration
public ConfiguredTaskAwaitable<T> ConfigureAwait(bool continueOnCapturedContext)
Parameters
Type | Name | Description |
---|---|---|
Boolean | continueOnCapturedContext | true to attempt to marshal the continuation back to the original context captured; otherwise, false. |
Returns
Type | Description |
---|---|
ConfiguredTaskAwaitable<T> | An object used to await asynchronous lazy initialization. |
GetAwaiter()
Gets awaiter for the asynchronous operation responsible for computing value.
Declaration
public TaskAwaiter<T> GetAwaiter()
Returns
Type | Description |
---|---|
TaskAwaiter<T> | The task awaiter. |
Reset()
Removes already computed value from the current object.
Declaration
public bool Reset()
Returns
Type | Description |
---|---|
Boolean | true if previous value is removed successfully; false if value is still computing or this instance is not resettable. |
ToString()
Returns textual representation of this object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The string representing this object. |