diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-11 15:18:02 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-11 15:18:02 +0200 |
commit | b475ba5cf146114a820b464e901b5129b2abfe84 (patch) | |
tree | a7855482df8f6cb602834bfbac256b3443d0fae5 /Utilities/LibMatrix.Utilities.Bot/Services | |
parent | Set timeout for command listener (diff) | |
download | LibMatrix-b475ba5cf146114a820b464e901b5129b2abfe84.tar.xz |
Fix bug with event sending, make initial sync detection deterministic
Diffstat (limited to 'Utilities/LibMatrix.Utilities.Bot/Services')
-rw-r--r-- | Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs | 13 |
1 files changed, 8 insertions, 5 deletions
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); } /// <summary>Triggered when the application host is performing a graceful shutdown.</summary> /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param> - 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); } } |