mirror of
https://github.com/ppy/osu.git
synced 2025-01-19 10:03:21 +08:00
Fix inline executions of APIRequest.Perform not getting result populated early enough
This commit is contained in:
parent
367c3e69c4
commit
801f02a3d7
@ -18,24 +18,32 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
public T Result { get; private set; }
|
public T Result { get; private set; }
|
||||||
|
|
||||||
protected APIRequest()
|
|
||||||
{
|
|
||||||
base.Success += () => TriggerSuccess(((OsuJsonWebRequest<T>)WebRequest)?.ResponseObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked on successful completion of an API request.
|
/// Invoked on successful completion of an API request.
|
||||||
/// This will be scheduled to the API's internal scheduler (run on update thread automatically).
|
/// This will be scheduled to the API's internal scheduler (run on update thread automatically).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public new event APISuccessHandler<T> Success;
|
public new event APISuccessHandler<T> Success;
|
||||||
|
|
||||||
|
protected override void PostProcess()
|
||||||
|
{
|
||||||
|
base.PostProcess();
|
||||||
|
Result = ((OsuJsonWebRequest<T>)WebRequest)?.ResponseObject;
|
||||||
|
}
|
||||||
|
|
||||||
internal void TriggerSuccess(T result)
|
internal void TriggerSuccess(T result)
|
||||||
{
|
{
|
||||||
if (Result != null)
|
if (Result != null)
|
||||||
throw new InvalidOperationException("Attempted to trigger success more than once");
|
throw new InvalidOperationException("Attempted to trigger success more than once");
|
||||||
|
|
||||||
Result = result;
|
Result = result;
|
||||||
Success?.Invoke(result);
|
|
||||||
|
TriggerSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void TriggerSuccess()
|
||||||
|
{
|
||||||
|
base.TriggerSuccess();
|
||||||
|
Success?.Invoke(Result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +107,8 @@ namespace osu.Game.Online.API
|
|||||||
if (checkAndScheduleFailure())
|
if (checkAndScheduleFailure())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
PostProcess();
|
||||||
|
|
||||||
API.Schedule(delegate
|
API.Schedule(delegate
|
||||||
{
|
{
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
@ -107,7 +117,14 @@ namespace osu.Game.Online.API
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void TriggerSuccess()
|
/// <summary>
|
||||||
|
/// Perform any post-processing actions after a successful request.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void PostProcess()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
internal virtual void TriggerSuccess()
|
||||||
{
|
{
|
||||||
Success?.Invoke();
|
Success?.Invoke();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user