1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 10:12:53 +08:00

Make connect/disconnect private

This commit is contained in:
Dean Herbert 2021-01-25 17:02:24 +09:00
parent 13e0423ed8
commit c05ae3497a

View File

@ -25,6 +25,8 @@ namespace osu.Game.Online.Multiplayer
private readonly Bindable<bool> isConnected = new Bindable<bool>(); private readonly Bindable<bool> isConnected = new Bindable<bool>();
private readonly IBindable<APIState> apiState = new Bindable<APIState>(); private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private readonly SemaphoreSlim connectionLock = new SemaphoreSlim(1);
[Resolved] [Resolved]
private IAPIProvider api { get; set; } = null!; private IAPIProvider api { get; set; } = null!;
@ -52,20 +54,16 @@ namespace osu.Game.Online.Multiplayer
{ {
case APIState.Failing: case APIState.Failing:
case APIState.Offline: case APIState.Offline:
Task.Run(Disconnect).CatchUnobservedExceptions(); Task.Run(() => disconnect(true)).CatchUnobservedExceptions();
break; break;
case APIState.Online: case APIState.Online:
Task.Run(Connect).CatchUnobservedExceptions(); Task.Run(connect).CatchUnobservedExceptions();
break; break;
} }
} }
private readonly SemaphoreSlim connectionLock = new SemaphoreSlim(1); private async Task connect()
public Task Disconnect() => disconnect(true);
protected async Task Connect()
{ {
cancelExistingConnect(); cancelExistingConnect();
@ -233,7 +231,7 @@ 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)
Task.Run(Connect, default).CatchUnobservedExceptions(); Task.Run(connect, default).CatchUnobservedExceptions();
return Task.CompletedTask; return Task.CompletedTask;
}; };