Created
July 20, 2020 13:12
-
-
Save kkokosa/c4d4e128da6ae574a53e10ad653fc3bc to your computer and use it in GitHub Desktop.
This file contains 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
class InCompletionOrderQuestion2 | |
{ | |
static async Task Main(string[] args) | |
{ | |
await InArrivalOrderFixed.DoWorkAsync(); | |
} | |
public static class InArrivalOrderFixed | |
{ | |
public static async Task DoWorkAsync() | |
{ | |
var numbers = new List<int> { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | |
foreach (var task in numbers.Select(x => CreateTask(x)).InCompletionOrder()) | |
{ | |
var delay = await task; | |
Console.WriteLine(delay); | |
} | |
static async Task<int> CreateTask(int i) | |
{ | |
await Task.Delay(1000 * i); | |
Console.WriteLine("Number: " + i); | |
return i; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment