Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
static void Main(string[] args)
{
Task.WaitAll(Execute(new int[] { 1, 2, 3, 4 }));
Console.ReadLine();
}
static async Task Execute(IEnumerable<int> values)
{
foreach (var task in AsyncEnumerable(values))
{
if (task is Task<string>)
{
var value = await ((Task<string>)task);
Console.WriteLine("Got value {0}", value);
}
else
{
await task;
}
}
}
static IEnumerable<Task> AsyncEnumerable(IEnumerable<int> values)
{
yield return WriteLineNoResult("Starting...");
foreach(var item in values)
{
Console.WriteLine("Start of loop body {0}", item);
yield return WriteLine(item.ToString());
Console.WriteLine("End of loop body {0}", item);
}
yield return WriteLineNoResult("Ending...");
}
static async Task WriteLineNoResult(string value)
{
Console.WriteLine(value);
await TaskEx.Delay(1000); // Such an expensive call.
}
static async Task<string> WriteLine(string value)
{
Console.WriteLine(value);
await TaskEx.Delay(1000); // Such an expensive call.
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.