Thread safety in await IAsyncEnumerable<T>
#118056
-
For example, List<string> failPathes = [];
await foreach (var t in Task.WhenEach(files2Upload.Select(f => UploadAsync(f.path, f.file))))
{
var failPath = await t;
if (failPath != string.Empty)
{
failPathes.Add(failPath);
Logger.LogError("upload fail:{path}", failPath);
}
}
return failPathes.Count == 0 ? string.Empty : $"upload failed files:{string.Join(';', failPathes)}"; Should the I guess NO after reading the source code of |
Beta Was this translation helpful? Give feedback.
Answered by
stephentoub
Jul 25, 2025
Replies: 1 comment 4 replies
-
await foreach processes the loop body sequentially. It does not introduce any parallelism. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
LeaFrock
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
await foreach processes the loop body sequentially. It does not introduce any parallelism.