Last active
April 4, 2017 02:51
-
-
Save mookid8000/e13a9dbdc60fc57cac7f62e49dfb09d2 to your computer and use it in GitHub Desktop.
ToListAsync task sequence extension for C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TaskExtensions | |
{ | |
public static async Task<List<TItem>> ToListAsync<TItem>(this IEnumerable<Task<TItem>> items) | |
{ | |
var tasks = items.Select(i => i).ToArray(); | |
await Task.WhenAll(tasks); | |
return tasks.Select(t => t.Result).ToList(); | |
} | |
} | |
/// usage: | |
var viewManagerAndPositions = await _viewManagers | |
.Select(async vm => new { ViewManager = vm, Position = await vm.GetPosition() }) | |
.ToListAsync(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment