Improved reliability of the shutdown process.
This commit is contained in:
parent
3f6007922c
commit
d94b1cb813
3 changed files with 47 additions and 63 deletions
SharpChat/ClientCommands
|
@ -2,10 +2,7 @@ using SharpChat.SockChat.S2CPackets;
|
|||
|
||||
namespace SharpChat.ClientCommands;
|
||||
|
||||
public class ShutdownRestartClientCommand(ManualResetEvent waitHandle, Func<bool> shutdownCheck) : ClientCommand {
|
||||
private readonly ManualResetEvent WaitHandle = waitHandle ?? throw new ArgumentNullException(nameof(waitHandle));
|
||||
private readonly Func<bool> ShutdownCheck = shutdownCheck ?? throw new ArgumentNullException(nameof(shutdownCheck));
|
||||
|
||||
public class ShutdownRestartClientCommand(CancellationTokenSource cancellationTokenSource) : ClientCommand {
|
||||
public bool IsMatch(ClientCommandContext ctx) {
|
||||
return ctx.NameEquals("shutdown")
|
||||
|| ctx.NameEquals("restart");
|
||||
|
@ -18,14 +15,16 @@ public class ShutdownRestartClientCommand(ManualResetEvent waitHandle, Func<bool
|
|||
return;
|
||||
}
|
||||
|
||||
if(!ShutdownCheck())
|
||||
if(cancellationTokenSource.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
Logger.Write("Shutdown requested through Sock Chat command...");
|
||||
|
||||
if(ctx.NameEquals("restart"))
|
||||
foreach(Connection conn in ctx.Chat.Connections)
|
||||
conn.PrepareForRestart();
|
||||
|
||||
await ctx.Chat.Update();
|
||||
WaitHandle?.Set();
|
||||
await cancellationTokenSource.CancelAsync();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue