added changed suggested by john

This commit is contained in:
arhamGIT committed 2023-02-01 03:29:22 -05:00
1 parent b4721882ec
commit 01eeadaf42
4 files changed
+433 -475

No files matched your search

+14 -5
View File
@@ -1,11 +1,14 @@
namespace spark_api_server {
using bts;
using System;
using System.Threading;
using System.Threading.Tasks;
class Program {
static int Main(string[] args) {
static async Task<int> Main(string[] args) {
Console.WriteLine("Starting spark_api_server... ");
var cancellationTokenSource = new CancellationTokenSource();
var sync = new bts.websocket_core.WebsocketDataSync();
var gwy = new bts.websocket_core.WebsocketConnectionGateway();
@@ -13,10 +16,16 @@
gwy.init(sync);
sync.init(gwy);
gwy.start_listening(prms);
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}");
}
var cancellationTokenSource = new CancellationTokenSource();
});
var task = Task.Run(() => {
while (!cancellationTokenSource.IsCancellationRequested) {
// Do something that can be interrupted
@@ -26,7 +35,7 @@
Console.WriteLine("Press any key to stop the server...");
Console.ReadKey();
cancellationTokenSource.Cancel();
task.Wait();
await Task.WhenAny(task, listen);
return 0;
}
}