Skip to content

Instantly share code, notes, and snippets.

@webJose
Created June 25, 2018 06:36
Show Gist options
  • Save webJose/4f777feffcb1bd4b55dc26bc9e9aa3fc to your computer and use it in GitHub Desktop.
Save webJose/4f777feffcb1bd4b55dc26bc9e9aa3fc to your computer and use it in GitHub Desktop.
Process pending async tasks in the order they are completed.
public static class TaskExtensions
{
    public static async Task<Task> ProcessCompleted(this IList<Task> tasks)
    {
        if (tasks == null)
        {
            throw new ArgumentNullException(nameof(tasks));
        }
        Task completedTask = await Task.WhenAny(tasks);
        tasks.Remove(completedTask);
        return completedTask;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment