Browse Source

ETCancellationTokenSource在Cancel之后调用Dispose,防止using的用法取消了却没调用Dispose

tanghai 6 years ago
parent
commit
89854eeaaa
1 changed files with 4 additions and 21 deletions
  1. 4 21
      Unity/Assets/Model/Base/Async/ETCancellationTokenSource.cs

+ 4 - 21
Unity/Assets/Model/Base/Async/ETCancellationTokenSource.cs

@@ -27,32 +27,15 @@ namespace ETModel
 
         public void Cancel()
         {
-            if (this.CancellationTokenSource == null)
-            {
-                return;
-            }
-            CancellationTokenSource cts = this.CancellationTokenSource;
-            this.CancellationTokenSource = null;
-            cts?.Cancel();
+            this.CancellationTokenSource.Cancel();
+            this.Dispose();
         }
 
         public async ETVoid CancelAfter(long afterTimeCancel)
         {
-            if (this.CancellationTokenSource == null)
-            {
-                return;
-            }
-            
             await Game.Scene.GetComponent<TimerComponent>().WaitAsync(afterTimeCancel);
-            
-            if (this.CancellationTokenSource == null)
-            {
-                return;
-            }
-            
-            CancellationTokenSource cts = this.CancellationTokenSource;
-            this.CancellationTokenSource = null;
-            cts?.Cancel();
+            this.CancellationTokenSource.Cancel();
+            this.Dispose();
         }
 
         public CancellationToken Token