using System.Collections.Generic;
using System.Threading.Tasks;
public static async Task Main()
var root = await GatherAsync().FirstOrDefaultAsync();
Console.WriteLine(root.Children.Count);
static async IAsyncEnumerable<Node> GatherAsync()
for(int i = 0; i < 5; i++)
var node = await GenerateNodeAsync(root);
static async Task<Node> GenerateNodeAsync(Node parent)
await Task.Delay(Random.Shared.Next(1, 50));
return new Node() { Parent = parent };
public Node Parent { get; set; }
public List<Node> Children { get; set; } = new List<Node>();