Class AsyncStateTracker
Represents tracker of the resource state.
Inherited Members
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 SourceAsyncStateTracker()
Initializes a new tracker.
Declaration
public AsyncStateTracker()
Properties
View SourceConcurrencyLevel
Sets the expected number of concurrent flows.
Declaration
public long ConcurrencyLevel { get; init; }
Property Value
| Type | Description |
|---|---|
| long |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
CurrentState
Gets the token that represents the current state.
Declaration
public AsyncStateTracker.Token CurrentState { get; }
Property Value
| Type | Description |
|---|---|
| AsyncStateTracker.Token |
IsCompleted
Gets a value indicating that this tracker is completed.
Declaration
public bool IsCompleted { get; }
Property Value
| Type | Description |
|---|---|
| bool |
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 SourceTryAdvance()
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. |
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. |
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. |
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. |
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. |