Skip to content

Commit

Permalink
Fixed generator and cleanup bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-gilliam committed Nov 7, 2023
1 parent 12304bf commit 53d5624
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -51,6 +54,8 @@ public void Start()

public void Stop()
{
_logger.Information("Stopping game timer...");

_subscriber.Dispose();
_cancelToken.Cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ public KernelService(IOptions<Settings> 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()
Expand Down

0 comments on commit 53d5624

Please sign in to comment.