about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-11 15:18:02 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-11 15:18:02 +0200
commitb475ba5cf146114a820b464e901b5129b2abfe84 (patch)
treea7855482df8f6cb602834bfbac256b3443d0fae5 /Utilities/LibMatrix.Utilities.Bot
parentSet timeout for command listener (diff)
downloadLibMatrix-b475ba5cf146114a820b464e901b5129b2abfe84.tar.xz
Fix bug with event sending, make initial sync detection deterministic
Diffstat (limited to 'Utilities/LibMatrix.Utilities.Bot')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs13
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);
     }
 }