mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 19:45:43 +08:00
Make OperationCanceledException throwing behaviour consistent
This commit is contained in:
parent
9f89b4e6d7
commit
d24d236468
@ -12,6 +12,7 @@ using Newtonsoft.Json;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
|
using osu.Game.Extensions;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
|
|
||||||
@ -51,11 +52,11 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
{
|
{
|
||||||
case APIState.Failing:
|
case APIState.Failing:
|
||||||
case APIState.Offline:
|
case APIState.Offline:
|
||||||
Task.Run(Disconnect);
|
Task.Run(Disconnect).CatchUnobservedExceptions();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case APIState.Online:
|
case APIState.Online:
|
||||||
Task.Run(Connect);
|
Task.Run(Connect).CatchUnobservedExceptions();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,8 +79,10 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
// if cancelled, we can be sure that a disconnect or reconnect is handled elsewhere.
|
// if cancelled, we can be sure that a disconnect or reconnect is handled elsewhere.
|
||||||
var cancellationToken = connectCancelSource.Token;
|
var cancellationToken = connectCancelSource.Token;
|
||||||
|
|
||||||
while (api.State.Value == APIState.Online && !cancellationToken.IsCancellationRequested)
|
while (api.State.Value == APIState.Online)
|
||||||
{
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
Logger.Log("Multiplayer client connecting...", LoggingTarget.Network);
|
Logger.Log("Multiplayer client connecting...", LoggingTarget.Network);
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -96,7 +99,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
//connection process was cancelled.
|
//connection process was cancelled.
|
||||||
return;
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -222,7 +225,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
newConnection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
|
newConnection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
|
||||||
newConnection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
|
newConnection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
|
||||||
|
|
||||||
newConnection.Closed += async ex =>
|
newConnection.Closed += ex =>
|
||||||
{
|
{
|
||||||
isConnected.Value = false;
|
isConnected.Value = false;
|
||||||
|
|
||||||
@ -230,7 +233,9 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
|
|
||||||
// make sure a disconnect wasn't triggered (and this is still the active connection).
|
// make sure a disconnect wasn't triggered (and this is still the active connection).
|
||||||
if (!cancellationToken.IsCancellationRequested)
|
if (!cancellationToken.IsCancellationRequested)
|
||||||
await Connect();
|
Task.Run(Connect, default).CatchUnobservedExceptions();
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
};
|
};
|
||||||
return newConnection;
|
return newConnection;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user