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
1 changed files with 12 additions and 8 deletions

View File

@ -51,21 +51,25 @@ private void load()
{
if (!connected.NewValue)
{
startedEvent.Set();
// messaging to the user about this disconnect will be provided by the RealtimeMatchSubScreen.
Schedule(PerformImmediateExit);
failAndBail();
}
}, 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)))
{
Logger.Log("Failed to start the multiplayer match in time.", LoggingTarget.Runtime, LogLevel.Important);
failAndBail("Failed to start the multiplayer match in time.");
}
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();