소스 검색

Short circuit on pre-cancelled token

Oren Novotny 9 년 전
부모
커밋
f50dec7ceb
1개의 변경된 파일7개의 추가작업 그리고 0개의 파일을 삭제
  1. 7 0
      Ix.NET/Source/System.Interactive.Async/AsyncIterator.cs

+ 7 - 0
Ix.NET/Source/System.Interactive.Async/AsyncIterator.cs

@@ -84,6 +84,13 @@ namespace System.Linq
                     return false;
                 }
 
+                // Short circuit and don't even call MoveNexCore
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    Dispose();
+                    return false;
+                }
+
                 // We keep these because cancelling any of these must trigger dispose of the iterator
                 moveNextRegistrations.Add(cancellationToken.Register(Dispose));