Commit d1186db 1 parent 768f18c commit d1186db Copy full SHA for d1186db
File tree 3 files changed +34
-2
lines changed
3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1
- namespace SuperLinq . Async ;
1
+ namespace SuperLinq . Async ;
2
2
3
3
public static partial class AsyncSuperEnumerable
4
4
{
@@ -42,6 +42,7 @@ static async IAsyncEnumerable<IList<TSource>> Core(
42
42
if ( n == size )
43
43
{
44
44
yield return array ;
45
+ array = null ;
45
46
n = 0 ;
46
47
}
47
48
}
Original file line number Diff line number Diff line change 1
- namespace Test . Async ;
1
+ namespace Test . Async ;
2
2
3
3
public sealed class BatchTest
4
4
{
@@ -17,6 +17,20 @@ public void BatchValidatesSize()
17
17
. Batch ( 0 ) ) ;
18
18
}
19
19
20
+ [ Fact ]
21
+ public async Task BatchDoesNotReturnSameArrayInstance ( )
22
+ {
23
+ await using var seq = Enumerable . Range ( 1 , 4 ) . AsTestingSequence ( ) ;
24
+ await using var e = seq . Batch ( 2 ) . GetAsyncEnumerator ( ) ;
25
+
26
+ _ = await e . MoveNextAsync ( ) ;
27
+ var batch1 = e . Current ;
28
+ _ = await e . MoveNextAsync ( ) ;
29
+ var batch2 = e . Current ;
30
+
31
+ Assert . NotEqual ( batch1 , batch2 ) ;
32
+ }
33
+
20
34
[ Fact ]
21
35
public async Task BatchWithEmptySource ( )
22
36
{
Original file line number Diff line number Diff line change @@ -44,6 +44,23 @@ public static IEnumerable<object[]> GetFourElementSequences() =>
44
44
. GetListSequences ( )
45
45
. Select ( x => new object [ ] { x } ) ;
46
46
47
+ [ Theory ]
48
+ [ MemberData ( nameof ( GetFourElementSequences ) ) ]
49
+ public void BatchDoesNotReturnSameArrayInstance ( IDisposableEnumerable < int > seq )
50
+ {
51
+ using ( seq )
52
+ {
53
+ using var e = seq . Batch ( 2 ) . GetEnumerator ( ) ;
54
+
55
+ _ = e . MoveNext ( ) ;
56
+ var batch1 = e . Current ;
57
+ _ = e . MoveNext ( ) ;
58
+ var batch2 = e . Current ;
59
+
60
+ Assert . NotEqual ( batch1 , batch2 ) ;
61
+ }
62
+ }
63
+
47
64
[ Theory ]
48
65
[ MemberData ( nameof ( GetFourElementSequences ) ) ]
49
66
public void BatchModifiedBeforeMoveNextDoesNotAffectNextBatch ( IDisposableEnumerable < int > seq )
You can’t perform that action at this time.
0 commit comments