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.
This commit is contained in:
John Colvin committed 2023-03-20 13:26:43 -04:00
1 parent ea5156122c
commit fa0e6f7c10
1 file changed
+8 -23
+8 -23
View File
@@ -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<int> _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;
}
}