From fa0e6f7c10292f0384eebead7a132562c2a71f27 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 15 Feb 2023 16:00:22 -0500 Subject: [PATCH] fix: Get rid of 'Press any key to cancel' prompt Console.Read throws an exception when running on linux. Furthermore, the process can still be killed w/ ctrl+c so this doesn't remove any functionality. --- src/client/spark_api_server/Program.cs | 31 +++++++------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/client/spark_api_server/Program.cs b/src/client/spark_api_server/Program.cs index 320541345..6689cd513 100644 --- a/src/client/spark_api_server/Program.cs +++ b/src/client/spark_api_server/Program.cs @@ -8,7 +8,6 @@ using System; using System.Reactive.Linq; - using System.Threading; using System.Threading.Tasks; class Program { @@ -26,7 +25,6 @@ static async Task _run(RunOptions opts) { Console.WriteLine("Starting spark_api_server... "); - var cancellationTokenSource = new CancellationTokenSource(); Log.notnull(opts.user); Log.notnull(opts.password); var service_ctx = ServiceContext.create(opts.sparkd); @@ -39,27 +37,14 @@ gwy.init(sync); sync.init(gwy); var errors = Errors.None; - var listen = Task.Run(async () => { - Log.Api.info("Starting websocket server..."); - try { - await gwy.start_listening(prms); - Log.Api.info("Websocket server stopped without error"); - } catch (Exception ex) { - Log.Api.error($"Websocket server threw ex: {ex}"); - errors |= Errors.Listen; - } - - }); - var task = Task.Run(() => { - while (!cancellationTokenSource.IsCancellationRequested) { - // Do something that can be interrupted - } - }, cancellationTokenSource.Token); - - Console.WriteLine("Press any key to stop the server..."); - Console.ReadKey(); - cancellationTokenSource.Cancel(); - await Task.WhenAny(task, listen); + Log.Api.info("Starting websocket server..."); + try { + await gwy.start_listening(prms); + Log.Api.info("Websocket server stopped without error"); + } catch (Exception ex) { + Log.Api.error($"Websocket server threw ex: {ex}"); + errors |= Errors.Listen; + } return (int)errors; } }