Show / Hide Table of Contents

Class AsyncLazy<T>

Provides support for asynchronous lazy initialization.

Inheritance
object
AsyncLazy<T>
Implements
ISupplier<CancellationToken, Task<T>>
IFunctional<Func<CancellationToken, Task<T>>>
IResettable
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> : ISupplier<CancellationToken, Task<T>>, IFunctional<Func<CancellationToken, Task<T>>>, IResettable
Type Parameters
Name Description
T

The type of object that is being asynchronously initialized.

Constructors

| Edit this page View Source

AsyncLazy(Func<CancellationToken, Task<T>>, bool)

Initializes a new instance of lazy value.

Declaration
public AsyncLazy(Func<CancellationToken, Task<T>> valueFactory, bool resettable = false)
Parameters
Type Name Description
Func<CancellationToken, Task<T>> valueFactory

The function used to compute actual value.

bool 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 is null.

| Edit this page 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.

Properties

| Edit this page View Source

IsValueCreated

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

Declaration
public bool IsValueCreated { get; }
Property Value
Type Description
bool
| Edit this page View Source

Value

Gets value if it is already computed.

Declaration
public Result<T>? Value { get; }
Property Value
Type Description
Result<T>?

Methods

| Edit this page View Source

Reset()

Removes already computed value from the current object.

Declaration
public bool Reset()
Returns
Type Description
bool

true if previous value is removed successfully; false if value is still computing or this instance is not resettable.

| Edit this page 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()
| Edit this page View Source

WithCancellation(CancellationToken)

Gets already completed task or invokes the factory.

Declaration
public Task<T> WithCancellation(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
Task<T>

Lazy representation of the value.

Implements

ISupplier<T, TResult>
IFunctional<TDelegate>
IResettable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾