Show / Hide Table of Contents

Class AsyncLazy<T>

Provides support for asynchronous lazy initialization.

Inheritance
Object
AsyncLazy<T>
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncLazy<T>
Type Parameters
Name Description
T

The type of object that is being asynchronously initialized.

Constructors

| Improve this Doc View Source

AsyncLazy(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

Exceptions
Type Condition
ArgumentException

valueFactory doesn't refer to any method.

Properties

| Improve this Doc View Source

IsValueCreated

Gets a value that indicates whether a value has been computed.

Declaration
public bool IsValueCreated { get; }
Property Value
Type Description
Boolean
| Improve this Doc View Source

Task

Gets task representing asynchronous computation of lazy value.

Declaration
public Task<T> Task { get; }
Property Value
Type Description
Task<T>
| Improve this Doc View Source

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 Source

ConfigureAwait(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.

| Improve this Doc View Source

GetAwaiter()

Gets awaiter for the asynchronous operation responsible for computing value.

Declaration
public TaskAwaiter<T> GetAwaiter()
Returns
Type Description
TaskAwaiter<T>

The task awaiter.

| Improve this Doc View Source

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.

| Improve this Doc View Source

ToString()

Returns textual representation of this object.

Declaration
public override string ToString()
Returns
Type Description
String

The string representing this object.

Overrides
Object.ToString()

Extension Methods

AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, CancellationToken)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>, out TResult1, out TResult2)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>)
ObjectExtensions.Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>)
ObjectExtensions.As<T>(T)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
ExpressionBuilder.Const<T>(T)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX