mirror of
https://github.com/ppy/osu.git
synced 2024-09-24 04:47:25 +08:00
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
|
// 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;
|
||
|
using System.Threading.Tasks;
|
||
|
using osu.Game.Online.API;
|
||
|
|
||
|
namespace osu.Game.Online.Notifications.Polling
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// A notifications client which polls for new messages every second.
|
||
|
/// </summary>
|
||
|
public class PollingNotificationsClient : NotificationsClient
|
||
|
{
|
||
|
private readonly IAPIProvider api;
|
||
|
|
||
|
public PollingNotificationsClient(IAPIProvider api)
|
||
|
: base(api)
|
||
|
{
|
||
|
this.api = api;
|
||
|
}
|
||
|
|
||
|
public override Task ConnectAsync(CancellationToken cancellationToken)
|
||
|
{
|
||
|
Task.Run(async () =>
|
||
|
{
|
||
|
while (!cancellationToken.IsCancellationRequested)
|
||
|
{
|
||
|
await api.PerformAsync(CreateFetchMessagesRequest());
|
||
|
await Task.Delay(1000, cancellationToken);
|
||
|
}
|
||
|
}, cancellationToken);
|
||
|
|
||
|
return Task.CompletedTask;
|
||
|
}
|
||
|
}
|
||
|
}
|