@@ -111,8 +111,15 @@ private async Task<IEnumerator<Tuple>> GetGreedyEnumeratorAsync(CancellationToke
111111 /// </summary>
112112 private async Task < IEnumerator < Tuple > > GetBatchedEnumeratorAsync ( CancellationToken token )
113113 {
114- EnumerationScope currentScope = null ;
115- var enumerator = await Source . GetEnumeratorAsync ( Context , token ) . ConfigureAwait ( false ) ;
114+ var currentScope = Context . Activate ( ) ;
115+ IEnumerator < Tuple > enumerator = null ;
116+ try {
117+ enumerator = await Source . GetEnumeratorAsync ( Context , token ) . ConfigureAwait ( false ) ;
118+ }
119+ finally {
120+ currentScope . DisposeSafely ( ) ;
121+ }
122+
116123 var batched = enumerator . ToEnumerable ( ) . Batch ( 2 ) ;
117124
118125 var cs = Context . BeginEnumeration ( ) ;
@@ -124,10 +131,11 @@ private async Task<IEnumerator<Tuple>> GetBatchedEnumeratorAsync(CancellationTok
124131 completableScope . Complete ( ) ;
125132 completableScope . Dispose ( ) ;
126133 } ;
127- return GetTwoLevelEnumerator ( batched , afterEnumerationAction , cs ) ;
134+ return GetTwoLevelEnumerator ( batched , afterEnumerationAction , cs ) ;
128135 }
129136
130- private static IEnumerator < Tuple > GetTwoLevelEnumerator ( IEnumerable < IEnumerable < Tuple > > enumerable , Action < object > afterEnumerationAction , object parameterForAction )
137+ private static IEnumerator < Tuple > GetTwoLevelEnumerator ( IEnumerable < IEnumerable < Tuple > > enumerable ,
138+ Action < object > afterEnumerationAction , ICompletableScope parameterForAction )
131139 {
132140 try {
133141 foreach ( var batch in enumerable )
0 commit comments