mirror of
https://github.com/ppy/osu.git
synced 2024-11-12 01:47:24 +08:00
Merge branch 'leaderboards' of https://github.com/DrabWeb/osu into leaderboards
This commit is contained in:
commit
e286356c4a
@ -60,15 +60,18 @@ namespace osu.Game.Online.API
|
||||
|
||||
private bool cancelled;
|
||||
|
||||
private Action pendingFailure;
|
||||
|
||||
public void Perform(APIAccess api)
|
||||
{
|
||||
if (cancelled) return;
|
||||
this.api = api;
|
||||
|
||||
if (checkAndProcessFailure())
|
||||
return;
|
||||
|
||||
if (startTime == null)
|
||||
startTime = DateTime.Now.TotalMilliseconds();
|
||||
|
||||
this.api = api;
|
||||
|
||||
if (remainingTime <= 0)
|
||||
throw new TimeoutException(@"API request timeout hit");
|
||||
|
||||
@ -76,9 +79,15 @@ namespace osu.Game.Online.API
|
||||
WebRequest.RetryCount = 0;
|
||||
WebRequest.Headers[@"Authorization"] = $@"Bearer {api.AccessToken}";
|
||||
|
||||
if (checkAndProcessFailure())
|
||||
return;
|
||||
|
||||
if (!WebRequest.Aborted) //could have been aborted by a Cancel() call
|
||||
WebRequest.BlockingPerform();
|
||||
|
||||
if (WebRequest.Completed)
|
||||
if (checkAndProcessFailure())
|
||||
return;
|
||||
|
||||
api.Scheduler.Add(delegate { Success?.Invoke(); });
|
||||
}
|
||||
|
||||
@ -89,10 +98,22 @@ namespace osu.Game.Online.API
|
||||
cancelled = true;
|
||||
|
||||
WebRequest?.Abort();
|
||||
api.Scheduler.Add(delegate
|
||||
|
||||
pendingFailure = () => Failure?.Invoke(e);
|
||||
checkAndProcessFailure();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checked for cancellation or error. Also queues up the Failed event if we can.
|
||||
/// </summary>
|
||||
/// <returns>Whether we are in a failed or cancelled state.</returns>
|
||||
private bool checkAndProcessFailure()
|
||||
{
|
||||
Failure?.Invoke(e);
|
||||
});
|
||||
if (api == null || pendingFailure == null) return cancelled;
|
||||
|
||||
api.Scheduler.Add(pendingFailure);
|
||||
pendingFailure = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user