Add pusher.Connected check before closing pusher.

This ensures that the pusher is only closed when it is connected, preventing unnecessary operations and potential errors. The change has been applied across ChatController, GamesController, and ChallengesController.
This commit is contained in:
Anduin Xue
2024-11-12 16:06:21 +00:00
parent 5063390b6d
commit fe3b04415c
3 changed files with 12 additions and 3 deletions
@@ -159,8 +159,11 @@ public class ChallengesController (
}
finally
{
await pusher.Close(HttpContext.RequestAborted);
outSub.Unsubscribe();
if (pusher.Connected)
{
await pusher.Close(HttpContext.RequestAborted);
}
}
}
}
@@ -52,9 +52,12 @@ public class ChatController(InMemoryDatabase database) : ControllerBase
}
finally
{
await pusher.Close(HttpContext.RequestAborted);
outSub.Unsubscribe();
inSub.Unsubscribe();
if (pusher.Connected)
{
await pusher.Close(HttpContext.RequestAborted);
}
}
}
}
@@ -90,9 +90,12 @@ public class GamesController(InMemoryDatabase database) : Controller
}
finally
{
await pusher.Close(HttpContext.RequestAborted);
outSub.Unsubscribe();
inSub.Unsubscribe();
if (pusher.Connected)
{
await pusher.Close(HttpContext.RequestAborted);
}
}
}