✅ How should I use SelectAsync?
I have this:
What is better way to call SelectAsync:
static public async Task<IEnumerable<TResult>> SelectAsync<TSource, TResult>(
this IEnumerable<TSource> @this,
Func<TSource, Task<TResult>> selector) =>
await Task.WhenAll(@this.Select(async x => await selector(x)
.ConfigureAwait(continueOnCapturedContext: false)))
.ConfigureAwait(continueOnCapturedContext: false);
static public async Task<IEnumerable<TResult>> SelectAsync<TSource, TResult>(
this IEnumerable<TSource> @this,
Func<TSource, Task<TResult>> selector) =>
await Task.WhenAll(@this.Select(async x => await selector(x)
.ConfigureAwait(continueOnCapturedContext: false)))
.ConfigureAwait(continueOnCapturedContext: false);
What is better way to call SelectAsync:
1.
public Task<List<ReportDefinitionDto>> ToDtos(
IEnumerable<ReportDefinitionModel> models,
CultureInfo culture) =>
models.SelectAsync(model => ToDto(model, culture))
.ToList();
1.
public Task<List<ReportDefinitionDto>> ToDtos(
IEnumerable<ReportDefinitionModel> models,
CultureInfo culture) =>
models.SelectAsync(model => ToDto(model, culture))
.ToList();
2.
public Task<List<ReportDefinitionDto>> ToDtos(
IEnumerable<ReportDefinitionModel> models,
CultureInfo culture) =>
models.SelectAsync(async model => await ToDto(model, culture))
.ToList();
2.
public Task<List<ReportDefinitionDto>> ToDtos(
IEnumerable<ReportDefinitionModel> models,
CultureInfo culture) =>
models.SelectAsync(async model => await ToDto(model, culture))
.ToList();
2 Replies