Share via


ValueSnapshot<T> Class

Definition

Provides an asynchronously initialized value that:

  • Can be awaited via GetValueAsync() until the first value or exception is set.
  • Exposes the latest value after it has been set (supports re-setting).
  • Tracks whether a value or exception was ever set via IsValueSet.
  • Supports setting an exception that will be thrown by GetValueAsync.

Thread-safe for concurrent SetValue / SetException / GetValueAsync calls.

public sealed class ValueSnapshot<T>
type ValueSnapshot<'T> = class
Public NotInheritable Class ValueSnapshot(Of T)

Type Parameters

T
Inheritance
ValueSnapshot<T>

Constructors

ValueSnapshot<T>()

Properties

IsValueSet

True once a value or exception has been set at least once.

Methods

GetValueAsync(CancellationToken)

Await the current value:

  • If a value has already been set, returns it immediately.
  • If an exception has been set, throws it.
  • Otherwise waits until the first value or exception is set. Always returns the latest value at the moment of completion or throws the exception.
SetException(Exception)

Sets an exception that will be thrown by GetValueAsync. The first successful call (either SetValue or SetException) completes any pending GetValueAsync waiters.

SetValue(T)

Sets (or updates) the value. The first successful call completes any pending GetValueAsync waiters. Subsequent calls replace the current value.

Applies to