From 53d56245e41480ec4cf49c1aba68e4bfa3b070ca Mon Sep 17 00:00:00 2001 From: Sean Gilliam Date: Tue, 7 Nov 2023 23:45:03 +0000 Subject: [PATCH] Fixed generator and cleanup bug --- .../CommandersCall.Kernel.Shared/Timers/GameTimer.cs | 9 +++++++-- .../CommandersCall.Kernel/KernelService.cs | 9 ++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/CommandersCall.Kernel/CommandersCall.Kernel.Shared/Timers/GameTimer.cs b/src/CommandersCall.Kernel/CommandersCall.Kernel.Shared/Timers/GameTimer.cs index 330eb41..6b3b146 100644 --- a/src/CommandersCall.Kernel/CommandersCall.Kernel.Shared/Timers/GameTimer.cs +++ b/src/CommandersCall.Kernel/CommandersCall.Kernel.Shared/Timers/GameTimer.cs @@ -32,16 +32,19 @@ public GameTimer(ILogger logger, int tickInterval) public void Update(int tickInterval) { + _logger.Information("Updating game timer from [{_tickInterval}] to [{tickInterval}]...", _tickInterval, tickInterval); + _tickInterval = Math.Clamp(tickInterval, _minTickValue, _maxTickValue); } public void Start() { + _logger.Information("Starting game timer..."); + _cancelToken = new CancellationTokenSource(); _tick = Observable - // .Interval(TimeSpan.FromMilliseconds(1000)) - .Generate(0L, i => !_cancelToken.IsCancellationRequested, i => i + 1, i => i, i => TimeSpan.FromMilliseconds(_minTickValue)) + .Generate(0L, i => !_cancelToken.IsCancellationRequested, i => 0L, i => i, i => TimeSpan.FromMilliseconds(_minTickValue)) .Window(() => Observable.Interval(TimeSpan.FromMilliseconds(_tickInterval))) .Select(x => x.LastAsync()) .Switch(); @@ -51,6 +54,8 @@ public void Start() public void Stop() { + _logger.Information("Stopping game timer..."); + _subscriber.Dispose(); _cancelToken.Cancel(); } diff --git a/src/CommandersCall.Kernel/CommandersCall.Kernel/KernelService.cs b/src/CommandersCall.Kernel/CommandersCall.Kernel/KernelService.cs index ddd9b3c..ea091d4 100644 --- a/src/CommandersCall.Kernel/CommandersCall.Kernel/KernelService.cs +++ b/src/CommandersCall.Kernel/CommandersCall.Kernel/KernelService.cs @@ -18,17 +18,20 @@ public KernelService(IOptions settings, ILogger logger) protected async override Task ExecuteAsync(CancellationToken cancellingToken) { - _logger.Information("Starting game timer..."); var timer = new GameTimer(_logger, _settings.gameTickInterval); timer.Start(); while (!cancellingToken.IsCancellationRequested) { //timer.Update(10000); - await Task.Delay(Timeout.InfiniteTimeSpan, cancellingToken); + await Task.Delay(Timeout.InfiniteTimeSpan, cancellingToken) + .ContinueWith(x => + { + // cleanup Isle 7 + timer.Stop(); + }); } - timer.Stop(); //TODO: develop more once tasks are implmemented // var tasks = AppDomain.CurrentDomain // .GetAssemblies()