Skip to content

Instantly share code, notes, and snippets.

@aevitas
Created September 24, 2019 13:53
Show Gist options
  • Save aevitas/2cd2e4e579f12c2d1eb48b691e4cb053 to your computer and use it in GitHub Desktop.
Save aevitas/2cd2e4e579f12c2d1eb48b691e4cb053 to your computer and use it in GitHub Desktop.
static async Task Main(string[] args)
{
await foreach (var num in GenerateNumbersAsync())
{
Console.WriteLine(num);
}
Console.ReadLine();
}
public static async IAsyncEnumerable<int> GenerateNumbersAsync()
{
for (int i = 0; i < 100; i++)
{
await Task.Delay(TimeSpan.FromSeconds(1));
yield return i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment