ARTICLE AD BOX
I'm working on a toy CLI debugger in C#/.NET. I have a REPL loop that looks something like this:
this.backgroundTcs = new TaskCompletionSource(); bool quit = false; while (!quit) { Task<string?> inputTask = Console.In.ReadLineAsync(); await Task.WhenAny(inputTask, backgroundTcs.Task); Console.WriteLine($"Status: {inputTask.Status}, {backgroundTcs.Task.Status}"); // do something with either of the tasks, depending on their IsCompleted properties if (inputTask.IsCompletedSuccessfully) { quit = DispatchDebuggerCommand(inputTask.Result); } }There is a background thread that simulates the execution of the debugged program. When that threads hits a break instruction, it calls the backgroundTcs completion source's SetResult method:
void OnBreakInstruction() { backroundTcs.SetResult(); // This does get executed (from the background thread) }My expectation is that the WhenAny call should resume after either a line of text has been read from the std input or the backgroundTcs.Task is completed. What I'm observing is that the call to SetResult is made, but the WhenAny method doesn't resume until after I hit the <Enter> key.
How can I write the code so that I can await either a command line being entered from the Console or a Task is completed?
