From cf01b4c60a70139a14bdb493c52a3549e663e38e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 10 Jul 2018 11:49:22 -0400 Subject: [PATCH] Slight async optimization to the DreamDaemonControlller Launch multiple tasks so they may execute concurrently before awaiting --- .../Controllers/DreamDaemonController.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 18aab9a9fe..816b13c8ca 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -161,14 +161,17 @@ namespace Tgstation.Server.Host.Controllers return Forbid(); var wd = instanceManager.GetInstance(Instance).Watchdog; - await wd.ChangeSettings(current, cancellationToken).ConfigureAwait(false); + + var changeSettingsTask = wd.ChangeSettings(current, cancellationToken); - //soft shutdown/restart can't be cancelled because of how many things rely on them - //They can be alternated though - if (!oldSoftRestart.Value && current.SoftRestart.Value) - await wd.Restart(true, cancellationToken).ConfigureAwait(false); - else if (!oldSoftShutdown.Value && current.SoftShutdown.Value) - await wd.Terminate(true, cancellationToken).ConfigureAwait(false); + //soft shutdown/restart can't be cancelled because of how many things rely on them + //They can be alternated though + if (!oldSoftRestart.Value && current.SoftRestart.Value) + await Task.WhenAll(changeSettingsTask, wd.Restart(true, cancellationToken)).ConfigureAwait(false); + else if (!oldSoftShutdown.Value && current.SoftShutdown.Value) + await Task.WhenAll(changeSettingsTask, wd.Terminate(true, cancellationToken)).ConfigureAwait(false); + else + await changeSettingsTask.ConfigureAwait(false); await DatabaseContext.Save(default).ConfigureAwait(false);