Skip to content

Commit b8c42e1

Browse files
committed
Introduce a single place where all public async overloads are maintained to evaluate design options using a single SUPPORT_FLAT_ASYNC_API flag.
1 parent 895cae3 commit b8c42e1

34 files changed

+672
-432
lines changed

Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerable.AsyncOverloads.cs

Lines changed: 398 additions & 200 deletions
Large diffs are not rendered by default.

Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerable.AsyncOverloads.tt

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@
1111
<#@ import namespace="System.Linq" #>
1212
<#@ import namespace="System.Reflection" #>
1313
<#@ output extension=".cs" #>
14-
#if SUPPORT_FLAT_ASYNC_API
15-
16-
using System.Collections.Generic;
17-
using System.Threading;
18-
using System.Threading.Tasks;
19-
20-
namespace System.Linq
21-
{
22-
partial class AsyncEnumerable
23-
{
2414
<#
2515
Func<Type, string> toCSharp = null;
2616
toCSharp = t =>
@@ -75,9 +65,21 @@ toCSharp = t =>
7565
return t.Name;
7666
}
7767
};
68+
#>
69+
using System.Collections.Generic;
70+
using System.Threading;
71+
using System.Threading.Tasks;
7872

79-
var methods = typeof(AsyncEnumerable).GetMethods(BindingFlags.Public | BindingFlags.Static);
80-
var asyncMethods = methods.Where(m => m.Name.Contains("Await")).OrderBy(m => m.Name).ThenBy(m => m.GetParameters().Length);
73+
namespace System.Linq
74+
{
75+
partial class AsyncEnumerable
76+
{
77+
<#
78+
var methods = typeof(AsyncEnumerable).GetMethods(BindingFlags.NonPublic | BindingFlags.Static);
79+
var asyncMethods = methods.Where(m => m.Name.Contains("Await") && m.Name.EndsWith("Core")).OrderBy(m => m.Name).ThenBy(m => m.GetParameters().Length);
80+
#>
81+
#if SUPPORT_FLAT_ASYNC_API
82+
<#
8183
foreach (var g in asyncMethods.GroupBy(m => m.Name.Contains("WithCancellation")))
8284
{
8385
if (g.Key)
@@ -91,7 +93,7 @@ foreach (var g in asyncMethods.GroupBy(m => m.Name.Contains("WithCancellation"))
9193
foreach (var m in g)
9294
{
9395
var longName = m.Name;
94-
var shortName = m.Name.Replace("WithCancellation", "").Replace("Await", "");
96+
var shortName = m.Name.Replace("WithCancellation", "").Replace("Await", "").Replace("Core", "");
9597
var genArgs = m.IsGenericMethod ? "<" + string.Join(", ", m.GetGenericArguments().Select(t => t.Name)) + ">" : "";
9698
var returnType = toCSharp(m.ReturnType);
9799
var isExtension = m.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), true);
@@ -110,7 +112,40 @@ foreach (var g in asyncMethods.GroupBy(m => m.Name.Contains("WithCancellation"))
110112
}
111113
}
112114
#>
115+
#else
116+
<#
117+
foreach (var g in asyncMethods.GroupBy(m => m.Name.Contains("WithCancellation")))
118+
{
119+
if (g.Key)
120+
{
121+
#>
122+
123+
#if !NO_DEEP_CANCELLATION
124+
<#
113125
}
114-
}
115126

127+
foreach (var m in g)
128+
{
129+
var longName = m.Name;
130+
var shortName = m.Name.Replace("Core", "");
131+
var genArgs = m.IsGenericMethod ? "<" + string.Join(", ", m.GetGenericArguments().Select(t => t.Name)) + ">" : "";
132+
var returnType = toCSharp(m.ReturnType);
133+
var isExtension = m.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), true);
134+
var pars = (isExtension ? "this " : "") + string.Join(", ", m.GetParameters().Select(p => toCSharp(p.ParameterType) + " " + p.Name));
135+
var args = string.Join(", ", m.GetParameters().Select(p => p.Name));
136+
#>
137+
public static <#=returnType#> <#=shortName#><#=genArgs#>(<#=pars#>) => <#=longName#><#=genArgs#>(<#=args#>);
138+
<#
139+
}
140+
141+
if (g.Key)
142+
{
143+
#>
116144
#endif
145+
<#
146+
}
147+
}
148+
#>
149+
#endif
150+
}
151+
}

Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Aggregate.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> _source, Func<TSo
4040
}
4141
}
4242

43-
public static ValueTask<TSource> AggregateAwaitAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, ValueTask<TSource>> accumulator, CancellationToken cancellationToken = default)
43+
internal static ValueTask<TSource> AggregateAwaitAsyncCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, ValueTask<TSource>> accumulator, CancellationToken cancellationToken = default)
4444
{
4545
if (source == null)
4646
throw Error.ArgumentNull(nameof(source));
@@ -71,7 +71,7 @@ static async ValueTask<TSource> Core(IAsyncEnumerable<TSource> _source, Func<TSo
7171
}
7272

7373
#if !NO_DEEP_CANCELLATION
74-
public static ValueTask<TSource> AggregateAwaitWithCancellationAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, CancellationToken, ValueTask<TSource>> accumulator, CancellationToken cancellationToken = default)
74+
internal static ValueTask<TSource> AggregateAwaitWithCancellationAsyncCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, CancellationToken, ValueTask<TSource>> accumulator, CancellationToken cancellationToken = default)
7575
{
7676
if (source == null)
7777
throw Error.ArgumentNull(nameof(source));
@@ -124,7 +124,7 @@ static async ValueTask<TAccumulate> Core(IAsyncEnumerable<TSource> _source, TAcc
124124
}
125125
}
126126

127-
public static ValueTask<TAccumulate> AggregateAwaitAsync<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, ValueTask<TAccumulate>> accumulator, CancellationToken cancellationToken = default)
127+
internal static ValueTask<TAccumulate> AggregateAwaitAsyncCore<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, ValueTask<TAccumulate>> accumulator, CancellationToken cancellationToken = default)
128128
{
129129
if (source == null)
130130
throw Error.ArgumentNull(nameof(source));
@@ -147,7 +147,7 @@ static async ValueTask<TAccumulate> Core(IAsyncEnumerable<TSource> _source, TAcc
147147
}
148148

149149
#if !NO_DEEP_CANCELLATION
150-
public static ValueTask<TAccumulate> AggregateAwaitWithCancellationAsync<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, ValueTask<TAccumulate>> accumulator, CancellationToken cancellationToken = default)
150+
internal static ValueTask<TAccumulate> AggregateAwaitWithCancellationAsyncCore<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, ValueTask<TAccumulate>> accumulator, CancellationToken cancellationToken = default)
151151
{
152152
if (source == null)
153153
throw Error.ArgumentNull(nameof(source));
@@ -194,7 +194,7 @@ static async ValueTask<TResult> Core(IAsyncEnumerable<TSource> _source, TAccumul
194194
}
195195
}
196196

197-
public static ValueTask<TResult> AggregateAwaitAsync<TSource, TAccumulate, TResult>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, ValueTask<TAccumulate>> accumulator, Func<TAccumulate, ValueTask<TResult>> resultSelector, CancellationToken cancellationToken = default)
197+
internal static ValueTask<TResult> AggregateAwaitAsyncCore<TSource, TAccumulate, TResult>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, ValueTask<TAccumulate>> accumulator, Func<TAccumulate, ValueTask<TResult>> resultSelector, CancellationToken cancellationToken = default)
198198
{
199199
if (source == null)
200200
throw Error.ArgumentNull(nameof(source));
@@ -219,7 +219,7 @@ static async ValueTask<TResult> Core(IAsyncEnumerable<TSource> _source, TAccumul
219219
}
220220

221221
#if !NO_DEEP_CANCELLATION
222-
public static ValueTask<TResult> AggregateAwaitWithCancellationAsync<TSource, TAccumulate, TResult>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, ValueTask<TAccumulate>> accumulator, Func<TAccumulate, CancellationToken, ValueTask<TResult>> resultSelector, CancellationToken cancellationToken = default)
222+
internal static ValueTask<TResult> AggregateAwaitWithCancellationAsyncCore<TSource, TAccumulate, TResult>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, ValueTask<TAccumulate>> accumulator, Func<TAccumulate, CancellationToken, ValueTask<TResult>> resultSelector, CancellationToken cancellationToken = default)
223223
{
224224
if (source == null)
225225
throw Error.ArgumentNull(nameof(source));

Ix.NET/Source/System.Linq.Async/System/Linq/Operators/All.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static async ValueTask<bool> Core(IAsyncEnumerable<TSource> _source, Func<TSourc
3333
}
3434
}
3535

36-
public static ValueTask<bool> AllAwaitAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate, CancellationToken cancellationToken = default)
36+
internal static ValueTask<bool> AllAwaitAsyncCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate, CancellationToken cancellationToken = default)
3737
{
3838
if (source == null)
3939
throw Error.ArgumentNull(nameof(source));
@@ -57,7 +57,7 @@ static async ValueTask<bool> Core(IAsyncEnumerable<TSource> _source, Func<TSourc
5757
}
5858

5959
#if !NO_DEEP_CANCELLATION
60-
public static ValueTask<bool> AllAwaitWithCancellationAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate, CancellationToken cancellationToken = default)
60+
internal static ValueTask<bool> AllAwaitWithCancellationAsyncCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate, CancellationToken cancellationToken = default)
6161
{
6262
if (source == null)
6363
throw Error.ArgumentNull(nameof(source));

Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Any.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static async ValueTask<bool> Core(IAsyncEnumerable<TSource> _source, Func<TSourc
4949
}
5050
}
5151

52-
public static ValueTask<bool> AnyAwaitAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate, CancellationToken cancellationToken = default)
52+
internal static ValueTask<bool> AnyAwaitAsyncCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<bool>> predicate, CancellationToken cancellationToken = default)
5353
{
5454
if (source == null)
5555
throw Error.ArgumentNull(nameof(source));
@@ -73,7 +73,7 @@ static async ValueTask<bool> Core(IAsyncEnumerable<TSource> _source, Func<TSourc
7373
}
7474

7575
#if !NO_DEEP_CANCELLATION
76-
public static ValueTask<bool> AnyAwaitWithCancellationAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate, CancellationToken cancellationToken = default)
76+
internal static ValueTask<bool> AnyAwaitWithCancellationAsyncCore<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<bool>> predicate, CancellationToken cancellationToken = default)
7777
{
7878
if (source == null)
7979
throw Error.ArgumentNull(nameof(source));

0 commit comments

Comments
 (0)