mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Add API methods to perform requests out-of-queue
This commit is contained in:
@ -7,6 +7,7 @@ using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -198,6 +199,22 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
}
|
||||
|
||||
public void Perform(APIRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
request.Perform(this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// todo: fix exception handling
|
||||
request.Fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Task PerformAsync(APIRequest request) =>
|
||||
Task.Factory.StartNew(() => Perform(request), TaskCreationOptions.LongRunning);
|
||||
|
||||
public void Login(string username, string password)
|
||||
{
|
||||
Debug.Assert(State == APIState.Offline);
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Users;
|
||||
@ -56,6 +57,10 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
}
|
||||
|
||||
public void Perform(APIRequest request) { }
|
||||
|
||||
public Task PerformAsync(APIRequest request) => Task.CompletedTask;
|
||||
|
||||
public void Register(IOnlineComponent component)
|
||||
{
|
||||
Scheduler.Add(delegate { components.Add(component); });
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Users;
|
||||
|
||||
@ -42,6 +43,24 @@ namespace osu.Game.Online.API
|
||||
/// <param name="request">The request to perform.</param>
|
||||
void Queue(APIRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Perform a request immediately, bypassing any API state checks.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Can be used to run requests as a guest user.
|
||||
/// </remarks>
|
||||
/// <param name="request">The request to perform.</param>
|
||||
void Perform(APIRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Perform a request immediately, bypassing any API state checks.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Can be used to run requests as a guest user.
|
||||
/// </remarks>
|
||||
/// <param name="request">The request to perform.</param>
|
||||
Task PerformAsync(APIRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Register a component to receive state changes.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user