Show / Hide Table of Contents

Class AsyncLazy<T>

Provides support for asynchronous lazy initialization.

Inheritance
Object
AsyncLazy<T>
Implements
ISupplier<CancellationToken, Task<T>>
IFunctional<DotNext.Func<, >>
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<, >>
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<CancellationToken, Task<T>>, Boolean)

Initializes a new instance of lazy value.

Declaration
public AsyncLazy(Func<CancellationToken, Task<T>> valueFactory, bool resettable = false)
Parameters
Type Name Description
DotNext.Func<CancellationToken, 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(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
DotNext.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.

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>
See Also
WithCancellation(CancellationToken)
| 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()
| Improve this Doc 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.

Explicit Interface Implementations

| Improve this Doc View Source

ISupplier<CancellationToken, Task<T>>.Invoke(CancellationToken)

Declaration
Task<T> ISupplier<CancellationToken, Task<T>>.Invoke(CancellationToken token)
Parameters
Type Name Description
CancellationToken token
Returns
Type Description
Task<T>

Implements

ISupplier<T, TResult>
IFunctional<TDelegate>

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)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
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
Supported by the .NET Foundation
☀
☾