From b475ba5cf146114a820b464e901b5129b2abfe84 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Wed, 11 Oct 2023 15:18:02 +0200 Subject: Fix bug with event sending, make initial sync detection deterministic --- .../Services/CommandListenerHostedService.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'Utilities') diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs index f56f9c1..6d2cba2 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs @@ -37,7 +37,7 @@ public class CommandListenerHostedService : IHostedService { private async Task? Run(CancellationToken cancellationToken) { _logger.LogInformation("Starting command listener!"); - var syncHelper = new SyncHelper(_hs); + var syncHelper = new SyncHelper(_hs, _logger); syncHelper.TimelineEventHandlers.Add(async @event => { try { var room = _hs.GetRoom(@event.RoomId); @@ -81,14 +81,17 @@ public class CommandListenerHostedService : IHostedService { _logger.LogError(e, "Error in command listener!"); } }); - await new SyncHelper(_hs){Timeout = 2500}.RunSyncLoopAsync(cancellationToken: cancellationToken); + await syncHelper.RunSyncLoopAsync(cancellationToken: cancellationToken); } /// Triggered when the application host is performing a graceful shutdown. /// Indicates that the shutdown process should no longer be graceful. - public Task StopAsync(CancellationToken cancellationToken) { + public async Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("Shutting down command listener!"); - _listenerTask.Wait(cancellationToken); - return Task.CompletedTask; + if (_listenerTask is null) { + _logger.LogError("Could not shut down command listener task because it was null!"); + return; + } + await _listenerTask.WaitAsync(cancellationToken); } } -- cgit 1.4.1