More correctly handle fire-and-forget async call

This commit is contained in:
Dean Herbert 2020-12-23 16:51:11 +09:00
parent 91021eb8c4
commit d27b83d678

View File

@ -51,21 +51,25 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
{ {
if (!connected.NewValue) if (!connected.NewValue)
{ {
startedEvent.Set();
// messaging to the user about this disconnect will be provided by the RealtimeMatchSubScreen. // messaging to the user about this disconnect will be provided by the RealtimeMatchSubScreen.
Schedule(PerformImmediateExit); failAndBail();
} }
}, true); }, true);
client.ChangeState(MultiplayerUserState.Loaded); client.ChangeState(MultiplayerUserState.Loaded).ContinueWith(task =>
failAndBail(task.Exception?.Message ?? "Server error"), TaskContinuationOptions.NotOnRanToCompletion);
if (!startedEvent.Wait(TimeSpan.FromSeconds(30))) if (!startedEvent.Wait(TimeSpan.FromSeconds(30)))
{ failAndBail("Failed to start the multiplayer match in time.");
Logger.Log("Failed to start the multiplayer match in time.", LoggingTarget.Runtime, LogLevel.Important); }
Schedule(PerformImmediateExit); private void failAndBail(string message = null)
} {
if (!string.IsNullOrEmpty(message))
Logger.Log(message, LoggingTarget.Runtime, LogLevel.Important);
startedEvent.Set();
Schedule(PerformImmediateExit);
} }
private void onMatchStarted() => startedEvent.Set(); private void onMatchStarted() => startedEvent.Set();