mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:03:13 +08:00
Use MRE with timeout to wait on match start
This commit is contained in:
parent
dece41d050
commit
81e2edc73f
@ -6,6 +6,8 @@ using System.Diagnostics;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Logging;
|
||||||
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.RealtimeMultiplayer;
|
using osu.Game.Online.RealtimeMultiplayer;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -26,7 +28,7 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
private StatefulMultiplayerClient client { get; set; }
|
private StatefulMultiplayerClient client { get; set; }
|
||||||
|
|
||||||
private readonly TaskCompletionSource<bool> resultsReady = new TaskCompletionSource<bool>();
|
private readonly TaskCompletionSource<bool> resultsReady = new TaskCompletionSource<bool>();
|
||||||
private bool started;
|
private readonly ManualResetEventSlim startedEvent = new ManualResetEventSlim();
|
||||||
|
|
||||||
public RealtimePlayer(PlaylistItem playlistItem)
|
public RealtimePlayer(PlaylistItem playlistItem)
|
||||||
: base(playlistItem, false)
|
: base(playlistItem, false)
|
||||||
@ -43,11 +45,19 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
client.ResultsReady += onResultsReady;
|
client.ResultsReady += onResultsReady;
|
||||||
client.ChangeState(MultiplayerUserState.Loaded);
|
client.ChangeState(MultiplayerUserState.Loaded);
|
||||||
|
|
||||||
while (!started)
|
if (!startedEvent.Wait(TimeSpan.FromSeconds(30)))
|
||||||
Thread.Sleep(100);
|
{
|
||||||
|
Logger.Log("Failed to start the multiplayer match in time.", LoggingTarget.Runtime, LogLevel.Important);
|
||||||
|
|
||||||
|
Schedule(() =>
|
||||||
|
{
|
||||||
|
ValidForResume = false;
|
||||||
|
this.Exit();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onMatchStarted() => started = true;
|
private void onMatchStarted() => startedEvent.Set();
|
||||||
|
|
||||||
private void onResultsReady() => resultsReady.SetResult(true);
|
private void onResultsReady() => resultsReady.SetResult(true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user