File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -16,25 +16,71 @@ public static IAsyncEnumerable<TSource> Concat<TSource>(this IAsyncEnumerable<IA
1616 if ( sources == null )
1717 throw Error . ArgumentNull ( nameof ( sources ) ) ;
1818
19+ #if USE_ASYNC_ITERATOR
20+ return Create ( Core ) ;
21+
22+ async IAsyncEnumerator < TSource > Core ( CancellationToken cancellationToken )
23+ {
24+ await foreach ( IAsyncEnumerable < TSource > source in sources . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
25+ {
26+ await foreach ( TSource item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
27+ {
28+ yield return item ;
29+ }
30+ }
31+ }
32+ #else
1933 return new ConcatAsyncEnumerableAsyncIterator < TSource > ( sources ) ;
34+ #endif
2035 }
2136
2237 public static IAsyncEnumerable < TSource > Concat < TSource > ( this IEnumerable < IAsyncEnumerable < TSource > > sources )
2338 {
2439 if ( sources == null )
2540 throw Error . ArgumentNull ( nameof ( sources ) ) ;
2641
42+ #if USE_ASYNC_ITERATOR
43+ return Create ( Core ) ;
44+
45+ async IAsyncEnumerator < TSource > Core ( CancellationToken cancellationToken )
46+ {
47+ foreach ( IAsyncEnumerable < TSource > source in sources )
48+ {
49+ await foreach ( TSource item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
50+ {
51+ yield return item ;
52+ }
53+ }
54+ }
55+ #else
2756 return ConcatCore ( sources ) ;
57+ #endif
2858 }
2959
3060 public static IAsyncEnumerable < TSource > Concat < TSource > ( params IAsyncEnumerable < TSource > [ ] sources )
3161 {
3262 if ( sources == null )
3363 throw Error . ArgumentNull ( nameof ( sources ) ) ;
3464
65+ #if USE_ASYNC_ITERATOR
66+ return Create ( Core ) ;
67+
68+ async IAsyncEnumerator < TSource > Core ( CancellationToken cancellationToken )
69+ {
70+ foreach ( IAsyncEnumerable < TSource > source in sources )
71+ {
72+ await foreach ( TSource item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
73+ {
74+ yield return item ;
75+ }
76+ }
77+ }
78+ #else
3579 return ConcatCore ( sources ) ;
80+ #endif
3681 }
3782
83+ #if ! USE_ASYNC_ITERATOR
3884 private static IAsyncEnumerable < TSource > ConcatCore < TSource > ( IEnumerable < IAsyncEnumerable < TSource > > sources )
3985 {
4086 return new ConcatEnumerableAsyncIterator < TSource > ( sources ) ;
@@ -218,4 +264,5 @@ protected override async ValueTask<bool> MoveNextCore()
218264 }
219265 }
220266 }
267+ #endif
221268}
You can’t perform that action at this time.
0 commit comments