2022-10-28 08:53:28 +00: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;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using osu.Game.Online.API;
|
2022-11-04 09:52:57 +00:00
|
|
|
using osu.Game.Online.Notifications;
|
2022-10-28 08:53:28 +00:00
|
|
|
|
2022-11-04 09:52:57 +00:00
|
|
|
namespace osu.Game.Tests
|
2022-10-28 08:53:28 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A notifications client which polls for new messages every second.
|
|
|
|
/// </summary>
|
|
|
|
public class PollingNotificationsClient : NotificationsClient
|
|
|
|
{
|
|
|
|
public PollingNotificationsClient(IAPIProvider api)
|
|
|
|
: base(api)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task ConnectAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
Task.Run(async () =>
|
|
|
|
{
|
|
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
|
|
{
|
2022-12-16 09:16:26 +00:00
|
|
|
await API.PerformAsync(CreateInitialFetchRequest()).ConfigureAwait(true);
|
|
|
|
await Task.Delay(1000, cancellationToken).ConfigureAwait(true);
|
2022-10-28 08:53:28 +00:00
|
|
|
}
|
|
|
|
}, cancellationToken);
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|