File tree Expand file tree Collapse file tree
Runtime/StateGraph/Extensions/ScriptableCommandExtension Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Change Log
22
3+ ## [ 0.8.1-beta] - Aug 25, 2024
4+ - Refactored the CommandState (Available when using the ScriptableCommands package) to better handle exceptions and clean up of cancellation tokens.
5+
36## [ 0.8.0-beta] - Aug 25, 2024
47- Added support for shared data between states. The SharedData object is a generic data store.
58 - States can access shared data via ` this.SharedData `
Original file line number Diff line number Diff line change @@ -21,24 +21,35 @@ public class CommandState : State
2121
2222 public override void OnEnterState ( )
2323 {
24- ExecuteCommands ( ) ;
24+ _cts = new CancellationTokenSource ( ) ;
25+ _ = ExecuteCommands ( ) ;
2526 }
2627
2728 public override void OnExitState ( )
2829 {
29- //...
30+ if ( _cts == null ) return ;
31+
32+ _cts . Cancel ( ) ;
33+ _cts . Dispose ( ) ;
34+ _cts = null ;
3035 }
3136
32- private async void ExecuteCommands ( )
37+ private async Task ExecuteCommands ( )
3338 {
34- await ExecuteCommandsAsync ( ) ;
39+ try
40+ {
41+ await ExecuteCommandsAsync ( ) ;
42+ }
43+ catch ( Exception ex )
44+ {
45+ Debug . LogError ( $ "Error executing commands: { ex } ") ;
46+ }
47+
3548 OnComplete ? . Invoke ( ) ;
3649 }
3750
3851 private async Task ExecuteCommandsAsync ( )
3952 {
40- _cts = new CancellationTokenSource ( ) ;
41-
4253 try
4354 {
4455 foreach ( var command in _commands )
@@ -50,10 +61,6 @@ private async Task ExecuteCommandsAsync()
5061 {
5162 Debug . Log ( "Command execution was cancelled." ) ;
5263 }
53- finally
54- {
55- _cts ? . Dispose ( ) ;
56- }
5764 }
5865 }
5966}
You can’t perform that action at this time.
0 commit comments