Skip to content

Commit c23cab4

Browse files
committed
Added basic extensions for tasks
1 parent 981978c commit c23cab4

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/MADE.Threading/TaskExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace MADE.Threading
55
{
66
using System;
7+
using System.Collections.Generic;
78
using System.Threading.Tasks;
89

910
/// <summary>
@@ -51,5 +52,25 @@ public static Task<T> AndObserveExceptions<T>(this Task<T> task, Action<Exceptio
5152

5253
return task;
5354
}
55+
56+
/// <summary>
57+
/// Creates a task that will complete when all of the <see cref="Task"/> objects in the collection have completed.
58+
/// </summary>
59+
/// <param name="tasks">The tasks to wait on for completion.</param>
60+
/// <returns>A task that represents the completion of all of the supplied tasks.</returns>
61+
public static async Task WhenAll(this IEnumerable<Task> tasks)
62+
{
63+
await Task.WhenAll(tasks);
64+
}
65+
66+
/// <summary>
67+
/// Creates a task that will complete when any of the <see cref="Task"/> objects in the collection have completed.
68+
/// </summary>
69+
/// <param name="tasks">The tasks to wait on for completion.</param>
70+
/// <returns>A task that represents the completion of one of the supplied tasks.</returns>
71+
public static async Task WhenAny(this IEnumerable<Task> tasks)
72+
{
73+
await Task.WhenAny(tasks);
74+
}
5475
}
5576
}

0 commit comments

Comments
 (0)