Class ManualResetCompletionSource
Represents base class for producer of value task.
Inheritance
Inherited Members
Namespace: DotNext.Threading.Tasks
Assembly: DotNext.Threading.dll
Syntax
public abstract class ManualResetCompletionSource
Fields
View SourceInitialCompletionToken
Represents initial value of the completion token when constructing a new instance of the completion source.
Declaration
protected const short InitialCompletionToken = -32768
Field Value
| Type | Description |
|---|---|
| short |
Properties
View SourceCompletionData
Gets a value passed to the manual completion method.
Declaration
public object? CompletionData { get; }
Property Value
| Type | Description |
|---|---|
| object |
IsCompleted
Gets a value indicating that this source is in signaled (completed) state.
Declaration
public bool IsCompleted { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
This property returns true if Status is WaitForConsumption or Consumed.
Status
Gets the status of this source.
Declaration
public ManualResetCompletionSourceStatus Status { get; }
Property Value
| Type | Description |
|---|---|
| ManualResetCompletionSourceStatus |
Methods
View SourceAfterConsumed()
Invokes when this source is ready to reuse.
Declaration
protected virtual void AfterConsumed()
Remarks
The default implementation releases the linked cancellation token registration, the timeout timer, and the captured continuation, so the consumed source is not rooted by them. In contrast to Reset(), it doesn't change the observable state of the source: the version, Status, and CompletionData remain intact until Reset() is called explicitly.
See Also
View SourceCleanUp()
Resets internal state of this source.
Declaration
protected virtual void CleanUp()
Reset()
Resets the state of the source.
Declaration
public short Reset()
Returns
| Type | Description |
|---|---|
| short | The version of the uncompleted task. |
Remarks
This method acts as a barrier for completion. It means that calling of this method guarantees that the task cannot be completed by the previously linked timeout or cancellation token.
The source can be reset when the previously created task is already consumed by its consumer, or when no consumer is attached to the task (a pending task can be abandoned this way). Calling this method while a consumer is awaiting the current task and the task is not yet consumed is not allowed: the awaiting consumer would never be resumed. In this case, the method throws InvalidOperationException.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | A consumer is subscribed to the current task, and the task is not yet consumed. |
TrySetCanceled(CancellationToken)
Attempts to complete the task unsuccessfully.
Declaration
public bool TrySetCanceled(CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | token | The canceled token. |
Returns
| Type | Description |
|---|---|
| bool | true if the result is completed successfully; false if the task has been canceled or timed out. |
TrySetCanceled<TOptions>(TOptions, CancellationToken)
Attempts to complete the task unsuccessfully.
Declaration
public bool TrySetCanceled<TOptions>(TOptions options, CancellationToken token) where TOptions : ManualResetCompletionSource.ICompletionOptions, allows ref struct
Parameters
| Type | Name | Description |
|---|---|---|
| TOptions | options | The completion options. |
| CancellationToken | token | The canceled token. |
Returns
| Type | Description |
|---|---|
| bool | true if the result is completed successfully; false if the task has been canceled or timed out. |
Type Parameters
| Name | Description |
|---|---|
| TOptions |
TrySetException(Exception)
Attempts to complete the task unsuccessfully.
Declaration
public bool TrySetException(Exception e)
Parameters
| Type | Name | Description |
|---|---|---|
| Exception | e | The exception to be returned to the consumer. |
Returns
| Type | Description |
|---|---|
| bool | true if the result is completed successfully; false if the task has been canceled or timed out. |
TrySetException<TOptions>(TOptions, Exception)
Attempts to complete the task unsuccessfully.
Declaration
public abstract bool TrySetException<TOptions>(TOptions options, Exception e) where TOptions : ManualResetCompletionSource.ICompletionOptions, allows ref struct
Parameters
| Type | Name | Description |
|---|---|---|
| TOptions | options | The completion options. |
| Exception | e | The exception to be returned to the consumer. |
Returns
| Type | Description |
|---|---|
| bool | true if the result is completed successfully; false if the task has been canceled or timed out. |
Type Parameters
| Name | Description |
|---|---|
| TOptions |