Extract majority of token retrieval code out of LoadComponentAsync for legibility

This commit is contained in:
Dean Herbert
2021-03-25 13:48:41 +09:00
parent ff139c2056
commit 4269cb7124

View File

@ -32,6 +32,13 @@ namespace osu.Game.Screens.Play
} }
protected override void LoadAsyncComplete() protected override void LoadAsyncComplete()
{
if (!handleTokenRetrieval()) return;
base.LoadAsyncComplete();
}
private bool handleTokenRetrieval()
{ {
// Token request construction should happen post-load to allow derived classes to potentially prepare DI backings that are used to create the request. // Token request construction should happen post-load to allow derived classes to potentially prepare DI backings that are used to create the request.
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
@ -39,7 +46,7 @@ namespace osu.Game.Screens.Play
if (!api.IsLoggedIn) if (!api.IsLoggedIn)
{ {
handleTokenFailure(new InvalidOperationException("API is not online.")); handleTokenFailure(new InvalidOperationException("API is not online."));
return; return false;
} }
var req = CreateTokenRequest(); var req = CreateTokenRequest();
@ -47,7 +54,7 @@ namespace osu.Game.Screens.Play
if (req == null) if (req == null)
{ {
handleTokenFailure(new InvalidOperationException("Request could not be constructed.")); handleTokenFailure(new InvalidOperationException("Request could not be constructed."));
return; return false;
} }
req.Success += r => req.Success += r =>
@ -60,8 +67,7 @@ namespace osu.Game.Screens.Play
api.Queue(req); api.Queue(req);
tcs.Task.Wait(); tcs.Task.Wait();
return true;
base.LoadAsyncComplete();
void handleTokenFailure(Exception exception) void handleTokenFailure(Exception exception)
{ {