Show / Hide Table of Contents

Class AsyncStateTracker

Represents tracker of the resource state.

Inheritance
object
AsyncStateTracker
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncStateTracker
Remarks

This class can be used to organize a stream of change notifications.

Constructors

View Source

AsyncStateTracker()

Initializes a new tracker.

Declaration
public AsyncStateTracker()

Properties

View Source

ConcurrencyLevel

Sets the expected number of concurrent flows.

Declaration
public long ConcurrencyLevel { get; init; }
Property Value
Type Description
long
Exceptions
Type Condition
ArgumentOutOfRangeException

value is not null and less than 1.

View Source

CurrentState

Gets the token that represents the current state.

Declaration
public AsyncStateTracker.Token CurrentState { get; }
Property Value
Type Description
AsyncStateTracker.Token
View Source

IsCompleted

Gets a value indicating that this tracker is completed.

Declaration
public bool IsCompleted { get; }
Property Value
Type Description
bool
View Source

IsNewerTokenAvailableAfterCompletion

Gets or sets a value indicating the behavior of the suspended and stale callers.

Declaration
public bool IsNewerTokenAvailableAfterCompletion { get; init; }
Property Value
Type Description
bool
Remarks

Producer thread can call TryAdvance() and then immediately TryComplete(). Consumer thread has outdated AsyncStateTracker.Token and on the next call to WaitNextAsync(Token, CancellationToken) method the behavior varies on this property. If it set to true then WaitNextAsync(Token, CancellationToken) returns a new instance of AsyncStateTracker.Token because there is a new version of the state is available. Otherwise, WaitNextAsync(Token, CancellationToken) returns null and the caller doesn't see the updated version.

Methods

View Source

TryAdvance()

Notifies suspended callers that the state has changed.

Declaration
public bool TryAdvance()
Returns
Type Description
bool

true if internal version of the resource is changed successfully; false if the tracker is completed.

View Source

TryAdvance(out bool)

Notifies suspended callers that the state has changed.

Declaration
public bool TryAdvance(out bool resumed)
Parameters
Type Name Description
bool resumed

true if at least one suspended caller is resumed; otherwise, false.

Returns
Type Description
bool

true if internal version of the resource is changed successfully; false if the tracker is completed.

View Source

TryComplete()

Completes state change notifications so any subsequent calls to WaitNextAsync(Token, CancellationToken) return immediately with null.

Declaration
public bool TryComplete()
Returns
Type Description
bool

true if the tracker is completed successfully; false if it's already completed.

View Source

TryComplete(out bool)

Completes state change notifications so any subsequent calls to WaitNextAsync(Token, CancellationToken) return immediately with null.

Declaration
public bool TryComplete(out bool resumed)
Parameters
Type Name Description
bool resumed

true if at least one suspended caller is resumed; otherwise, false.

Returns
Type Description
bool

true if the tracker is completed successfully; false if it's already completed.

View Source

WaitNextAsync(Token, CancellationToken)

Waits for the state token next after stateToken.

Declaration
public ValueTask<bool> WaitNextAsync(AsyncStateTracker.Token stateToken, CancellationToken token = default)
Parameters
Type Name Description
AsyncStateTracker.Token stateToken

The token that represents the current version of the resource.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<bool>

true if the next resource state is observed; false if tracker is in completed state and no new states will be observed.

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾