CommandPattern 1.0.0
This package contains a collection of classes and interfaces to allow for quick and consistent implementation of the command pattern across projects.
Public Member Functions | Protected Member Functions | Properties | Events | List of all members
SadSapphicGames.CommandPattern.AsyncCommand Class Referenceabstract

The base class of all commands who's execute method involves asynchronous tasks More...

Inheritance diagram for SadSapphicGames.CommandPattern.AsyncCommand:
SadSapphicGames.CommandPattern.Command SadSapphicGames.CommandPattern.IAsyncCommand SadSapphicGames.CommandPattern.ICommand SadSapphicGames.CommandPattern.ICommand

Public Member Functions

sealed override void Execute ()
 This method may not be overridden in asynchronous commands. Use ExecuteAsync for your command's logic instead. More...
 
abstract Task ExecuteAsync ()
 Executes the command asynchronously. Remember to add the async keyword as that is not considered part of the method signature and cannot be added to abstract methods.
IMPORTANT: if you want to be able to cancel the AsyncCommand's task you must invoke CancellationToken.ThrowIfCancellationRequested() within this method somewhere after the first await. If you do not do so attempting to cancel it will do nothing. More...
 
abstract void Execute ()
 Executes the command, do not invoke directly, instead use a CommandStream. More...
 
abstract void Execute ()
 Executes the function of the command More...
 
abstract Task ExecuteAsync ()
 This is where the logic of executing the command should be placed for an AsyncCommand, Execute should just store the return in CommandTask and setup the OnTaskCompleted method. Remember to make this method async as that isn't considered part of its signature. More...
 

Protected Member Functions

 AsyncCommand ()
 Created the cancellation token of the async command and sets up its disposal once the task completes (wether that is from success, cancellation, or faulting)
 

Properties

Task CommandTask [get]
 The task for the completion of the ExecuteAsync method after it reaches its first await and returns control back to the calling method (CommandStream.TryExecuteNext()) More...
 
CancellationToken CancellationToken [get, set]
 This can be used in ExecuteAsync to determine if the CommandTask has been canceled. More...
 
- Properties inherited from SadSapphicGames.CommandPattern.IAsyncCommand
Task CommandTask [get]
 This should get the asynchronous task returned by ExecuteAsync after it reaches its first await More...
 
CancellationToken CancellationToken [get, set]
 This can be used to Cancel the task after it has been started. More...
 

Events

Action OnTaskCompleted
 This event is invoked when CommandTask is completed. I.E. - when we reach the end of ExecuteAsync(). Subscribe to it to preform an action at after the command has fully completed.
 
Action OnTaskCanceled
 This event is invoked if the command task is canceled. Most bookkeeping that occurs in this situation is handled by the package but you can subscribe to this as well if needed.
 
Action< Exception > OnTaskFaulted
 This event is invoked if the command task throws an exception.

 
Action OnAnyTaskEnd
 This event is invoked when any of the OnTask[blank] events are to avoid needed to subscribe the same delegate to multiple events when logic needs to run regardless of how the task finished
 
- Events inherited from SadSapphicGames.CommandPattern.IAsyncCommand
Action OnTaskCompleted
 This event should be invoked when CommandTask is successfully completed.
 
Action OnTaskCanceled
 This event should be invoked when CommandTask is cancelled.
 
Action< Exception > OnTaskFaulted
 This event should be invoked when CommandTask throws an exception
 
Action OnAnyTaskEnd
 This event should be invoked when any of the above three are
 

Detailed Description

The base class of all commands who's execute method involves asynchronous tasks

Member Function Documentation

◆ Execute()

sealed override void SadSapphicGames.CommandPattern.AsyncCommand.Execute ( )
virtual

This method may not be overridden in asynchronous commands. Use ExecuteAsync for your command's logic instead.

Implements SadSapphicGames.CommandPattern.Command.

◆ ExecuteAsync()

abstract Task SadSapphicGames.CommandPattern.AsyncCommand.ExecuteAsync ( )
pure virtual

Executes the command asynchronously. Remember to add the async keyword as that is not considered part of the method signature and cannot be added to abstract methods.
IMPORTANT: if you want to be able to cancel the AsyncCommand's task you must invoke CancellationToken.ThrowIfCancellationRequested() within this method somewhere after the first await. If you do not do so attempting to cancel it will do nothing.

Returns
The task for the completion of this method after it reaches its first await and returns control to the calling method.

Implements SadSapphicGames.CommandPattern.IAsyncCommand.

Property Documentation

◆ CancellationToken

CancellationToken SadSapphicGames.CommandPattern.AsyncCommand.CancellationToken
getset

This can be used in ExecuteAsync to determine if the CommandTask has been canceled.

Implements SadSapphicGames.CommandPattern.IAsyncCommand.

◆ CommandTask

Task SadSapphicGames.CommandPattern.AsyncCommand.CommandTask
get

The task for the completion of the ExecuteAsync method after it reaches its first await and returns control back to the calling method (CommandStream.TryExecuteNext())

Implements SadSapphicGames.CommandPattern.IAsyncCommand.


The documentation for this class was generated from the following file: