Skip to content

Commit

Permalink
Add ability to skip failed tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArcaneBrony committed May 16, 2024
1 parent 6f6b8e4 commit 68eca20
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ArcaneLibs/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ public static T[] Add<T>(this T[] array, T item) {
}

//return task results async without preserving order
public static async IAsyncEnumerable<T> ToAsyncEnumerable<T>(this IEnumerable<Task<T>> tasks) {
public static async IAsyncEnumerable<T> ToAsyncEnumerable<T>(this IEnumerable<Task<T>> tasks, bool skipExceptions = false) {
var taskList = tasks.ToList();
while (taskList.Count > 0) {
var task = await Task.WhenAny(taskList);
taskList.Remove(task);
if(skipExceptions && task.IsFaulted) continue;
yield return await task;
}
}
Expand Down

0 comments on commit 68eca20

Please sign in to comment.