refactor: Init ServiceContext & login outside of data sync

The login process is asynchronous, so it doesn't really fit in the
(synchronous) 'WebsocketDataSync.init' fn. This also reduces some state
in WebsocketDataSync, which is always a good thing, as it makes the
ServiceContext member readonly, and allows it to assume the user is
already logged in.
This commit is contained in:
John Colvin committed 2023-03-20 13:26:41 -04:00
1 parent 97b974a31f
commit ea5156122c
5 files changed
+56 -6

No files matched your search

+16 -1
View File
@@ -1,7 +1,13 @@
namespace spark_api_server {
using bts;
using bts.api.core;
using CommandLine;
using Spark.Api.Server;
using System;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -14,10 +20,19 @@
}
static async Task<int> Main(string[] args) {
var res = Parser.Default.ParseArguments<RunOptions>(args);
return await res.MapResult(_run, errs => Task.FromResult(1));
}
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);
await service_ctx.login(opts.user, opts.password);
var sync = new bts.websocket_core.WebsocketDataSync();
var sync = new bts.websocket_core.WebsocketDataSync(service_ctx);
var gwy = new bts.websocket_core.WebsocketConnectionGateway();
var prms = new bts.websocket_core.WebsocketServerParams();