Skip to content

Instantly share code, notes, and snippets.

@kkokosa
Created July 20, 2020 13:12
Show Gist options
  • Save kkokosa/c4d4e128da6ae574a53e10ad653fc3bc to your computer and use it in GitHub Desktop.
Save kkokosa/c4d4e128da6ae574a53e10ad653fc3bc to your computer and use it in GitHub Desktop.
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