move a bunch of stuff into subfolders
This commit is contained in:
parent
8f281d65b2
commit
151cad4cee
1 changed files with 44 additions and 27 deletions
|
|
@ -1,37 +0,0 @@
|
|||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace TanksServer;
|
||||
|
||||
public class GameTickService(IEnumerable<ITickStep> steps) : IHostedService
|
||||
{
|
||||
private readonly CancellationTokenSource _cancellation = new();
|
||||
private readonly List<ITickStep> _steps = steps.ToList();
|
||||
private Task? _run;
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_run = RunAsync();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task RunAsync()
|
||||
{
|
||||
while (!_cancellation.IsCancellationRequested)
|
||||
{
|
||||
foreach (var step in _steps)
|
||||
await step.TickAsync();
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _cancellation.CancelAsync();
|
||||
if (_run != null) await _run;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ITickStep
|
||||
{
|
||||
Task TickAsync();
|
||||
}
|
||||
Reference in a new issue