Class CancellableOperationBase<T>
A base class for cancelable operations over various items, supporting separate cancellation per item.
Inherited Members
Namespace: Microsoft.XboxStudios.BotBrain.Operations
Assembly: BotBrain.Operations.dll
Syntax
public abstract class CancellableOperationBase<T> : ICancellableOperation<T>, IOperation<T>, ICancellableOperation, IOperation where T : notnull
Type Parameters
Name | Description |
---|---|
T | The item type. |
Properties
View SourceIsRunning
Gets a value indicating whether or not the operation is executing.
Declaration
public bool IsRunning { get; }
Property Value
Type | Description |
---|---|
bool |
Timeout
Gets an optional timeout.
Declaration
public TimeSpan Timeout { get; init; }
Property Value
Type | Description |
---|---|
TimeSpan |
Remarks
The operation will always timeout after the specified time, regardless of whether a cancellation token was passed or not.
Methods
View SourceCancel(T)
Cancels an operation running on a specific item.
Declaration
public void Cancel(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item. |
Cancel(T, bool)
Cancels an operation running on a specific item.
Declaration
protected void Cancel(T item, bool result)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item. |
bool | result | The result of the operation. |
ExecuteOn(T, CancellationToken)
Runs the operation on an item.
Declaration
protected abstract Task<bool> ExecuteOn(T item, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item. |
CancellationToken | token | A token to monitor for cancellation. |
Returns
Type | Description |
---|---|
Task<bool> | A task that returns a boolean indicating success or failure when the operation completes. |
GetAwaiter(T, CancellationToken)
Gets a task used to await this operation on an item.
Declaration
public Task<bool> GetAwaiter(T item, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to use. |
CancellationToken | token | A token to monitor for cancellation. |
Returns
Type | Description |
---|---|
Task<bool> | A task. |
IsRunningOn(T)
Gets a value indicating whether or not the operation is executing.
Declaration
public bool IsRunningOn(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to use. |
Returns
Type | Description |
---|---|
bool | True if the operation is executing on the item. |
Run(T)
Executes the operation on an item.
Declaration
public Task<bool> Run(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item. |
Returns
Type | Description |
---|---|
Task<bool> | A task that returns a boolean indicating success or failure when the operation completes. |
Run(T, CancellationToken)
Executes the operation on an item.
Declaration
public Task<bool> Run(T item, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item. |
CancellationToken | token | A token to monitor for cancellation. |
Returns
Type | Description |
---|---|
Task<bool> | A task that returns a boolean indicating success or failure when the operation completes. |
TryCreateCancellationToken(T, out CancellationToken)
Attempts to create a cancellation token for an operation on the given item.
Declaration
protected bool TryCreateCancellationToken(T item, out CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item. |
CancellationToken | token | The cancellation token. |
Returns
Type | Description |
---|---|
bool | True if a token could be created. |
Events
View SourceExecutionStateChanged
Occurs when the operation changes execution state on an item.
Declaration
public event EventHandler<OperationStateChangedInfo<T>>? ExecutionStateChanged
Event Type
Type | Description |
---|---|
EventHandler<OperationStateChangedInfo<T>> |