From b01ba1e2cdb223cb9c61c70ae8c8cbdbb28c2127 Mon Sep 17 00:00:00 2001 From: Laci0503 Date: Wed, 24 Jul 2024 11:07:04 +0200 Subject: [PATCH] Gateway disposes the subscriptions when closed --- Discord.API/Gateway/AbstractGateway.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Discord.API/Gateway/AbstractGateway.cs b/Discord.API/Gateway/AbstractGateway.cs index 0241548..16943e4 100644 --- a/Discord.API/Gateway/AbstractGateway.cs +++ b/Discord.API/Gateway/AbstractGateway.cs @@ -7,13 +7,14 @@ namespace Discord.API; public abstract class AbstractGateway { protected readonly IWebsocketClient WebsocketClient; protected readonly TimeProvider TimeProvider; + private List Subscriptions = new(3); public AbstractGateway(IWebsocketClient client, TimeProvider time_provider){ this.WebsocketClient = client; this.TimeProvider = time_provider; - WebsocketClient.DisconnectionHappened.Subscribe(DisconnectHandlerInternal); - WebsocketClient.ReconnectionHappened.Subscribe(ReconnectHandler); - WebsocketClient.MessageReceived.Subscribe(MessageReceivedHandler); + Subscriptions.Add(WebsocketClient.DisconnectionHappened.Subscribe(DisconnectHandlerInternal)); + Subscriptions.Add(WebsocketClient.ReconnectionHappened.Subscribe(ReconnectHandler)); + Subscriptions.Add(WebsocketClient.MessageReceived.Subscribe(MessageReceivedHandler)); WebsocketClient.Start(); } @@ -100,5 +101,9 @@ public abstract class AbstractGateway { public async Task Close(){ StopHeartbeat(); await WebsocketClient.Stop(System.Net.WebSockets.WebSocketCloseStatus.NormalClosure, "Shutdown"); + foreach (var sub in Subscriptions) + { + sub.Dispose(); + } } } \ No newline at end of file