1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-13 01:27:25 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomUpdater.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.4 KiB
C#
Raw Normal View History

2020-12-19 00:15:41 +09:00
// 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.Allocation;
using osu.Game.Online;
using osu.Game.Online.API;
2020-12-25 13:38:11 +09:00
using osu.Game.Online.Rooms;
2020-12-19 00:15:41 +09:00
namespace osu.Game.Screens.OnlinePlay.Playlists
2020-12-19 00:15:41 +09:00
{
/// <summary>
/// A <see cref="PollingComponent"/> that polls for and updates a room.
2020-12-19 00:15:41 +09:00
/// </summary>
public partial class PlaylistsRoomUpdater : PollingComponent
2020-12-19 00:15:41 +09:00
{
[Resolved]
private IAPIProvider api { get; set; } = null!;
private readonly Room room;
public PlaylistsRoomUpdater(Room room)
2020-12-19 00:15:41 +09:00
{
this.room = room;
2020-12-19 00:15:41 +09:00
}
private GetRoomRequest? lastPollRequest;
2020-12-19 00:15:41 +09:00
protected override Task Poll()
{
if (!api.IsLoggedIn)
2020-12-19 00:15:41 +09:00
return base.Poll();
if (room.RoomID == null)
2020-12-19 00:15:41 +09:00
return base.Poll();
lastPollRequest?.Cancel();
2020-12-19 00:15:41 +09:00
2025-02-12 18:35:35 +09:00
var tcs = new TaskCompletionSource<bool>();
var req = new GetRoomRequest(room.RoomID.Value);
req.Success += result =>
2020-12-19 00:15:41 +09:00
{
2025-02-12 18:35:35 +09:00
room.CopyFrom(result);
2020-12-19 00:15:41 +09:00
tcs.SetResult(true);
};
req.Failure += _ => tcs.SetResult(false);
api.Queue(req);
2020-12-19 00:15:41 +09:00
lastPollRequest = req;
2020-12-19 00:15:41 +09:00
return tcs.Task;
}
}
}