// concurrent test static async ChaosTask <ChaosUnit> SimpleConcurrentTest() { if (await ChaosTask.Concurrent <ChaosUnit>()) { Console.WriteLine("Parent."); } else { Console.WriteLine("Child."); } return(default(ChaosUnit)); }
// concurrent test static async ChaosTask <string> StartEchoServer() { Console.WriteLine("Start echo server."); Console.WriteLine("if you want to exit, Type 'end'."); var finished = ChaosBox.Create(false); var message = string.Empty; var isParent = await ChaosTask.Concurrent <string>(); if (isParent) { while (!finished.Value) { await ChaosTask.WaitNext <string>(); if (!string.IsNullOrEmpty(message)) { if (message == "end") { Console.WriteLine("byebye"); finished.Value = true; } else { Console.WriteLine($"your message:{message}"); } } } await ChaosTask.Yield <string>(); return(message); } else { while (!finished.Value) { async ChaosTask <ChaosUnit> sendMessage() { await Task.Run(() => { message = Console.ReadLine(); }); return(default(ChaosUnit)); } await ChaosTask.WaitTask <string>(sendMessage()); } return(string.Empty); } }