소스 검색

AsyncEnumerable.Take: Dispose source AsyncEnumerator as soon as possible, i.e. when it's clear that MoveNext will not be called again on that enumerator. The rationale behind this is:
1) Observable.Take disposes subscription on source as soon as n elements are observed, not when n+1 elements are observed (or source completes/faults).
2) We want to free resources as early as possible.
3) The outer enumerator may not be disposed at all. While this is clearly the user's fault, in this case, Ix can (and should) ensure that the source enumerator is disposed anyway.
4) From the unit tests, it seems that nothing depends on the current behaviour.

Daniel Weber 11 년 전
부모
커밋
009b14de43
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      Ix.NET/Source/System.Interactive.Async/AsyncEnumerable.Single.cs

+ 4 - 0
Ix.NET/Source/System.Interactive.Async/AsyncEnumerable.Single.cs

@@ -491,6 +491,10 @@ namespace System.Linq
                             t.Handle(tcs, res =>
                             {
                                 --n;
+
+                                if (n == 0)
+                                    e.Dispose();
+
                                 tcs.TrySetResult(res);
                             });
                         });