瀏覽代碼

limit cxl token scope

Oren Novotny 9 年之前
父節點
當前提交
235d2e692c
共有 1 個文件被更改,包括 1 次插入17 次删除
  1. 1 17
      Ix.NET/Source/System.Interactive.Async/AsyncIterator.cs

+ 1 - 17
Ix.NET/Source/System.Interactive.Async/AsyncIterator.cs

@@ -25,7 +25,6 @@ namespace System.Linq
             internal AsyncIteratorState state = AsyncIteratorState.New;
             internal TSource current;
             private CancellationTokenSource cancellationTokenSource;
-            private List<CancellationTokenRegistration> moveNextRegistrations;
             private bool currentIsInvalid = true;
 
             protected AsyncIterator()
@@ -41,7 +40,6 @@ namespace System.Linq
 
                 enumerator.state = AsyncIteratorState.Allocated;
                 enumerator.cancellationTokenSource = new CancellationTokenSource();
-                enumerator.moveNextRegistrations = new List<CancellationTokenRegistration>();
                 return enumerator;
             }
 
@@ -56,17 +54,6 @@ namespace System.Linq
 
                 current = default(TSource);
                 state = AsyncIteratorState.Disposed;
-
-                var toClean = moveNextRegistrations?.ToList();
-                moveNextRegistrations = null;
-                if (toClean != null)
-                {
-                    foreach (var r in toClean)
-                    {
-                        r.Dispose();
-                    }
-                    toClean.Clear();
-                }
             }
 
             public TSource Current
@@ -85,11 +72,8 @@ namespace System.Linq
                 {
                     return false;
                 }
-               
-
-                // We keep these because cancelling any of these must trigger dispose of the iterator
-                moveNextRegistrations.Add(cancellationToken.Register(Dispose));
 
+                using (cancellationToken.Register(Dispose))
                 using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, cancellationTokenSource.Token))
                 {
                     try