2022-10-27 05:34:24 +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;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace osu.Game.Online
|
|
|
|
{
|
2022-11-02 02:43:22 +00:00
|
|
|
public abstract class PersistentEndpointClient : IAsyncDisposable
|
2022-10-27 05:34:24 +00:00
|
|
|
{
|
2022-11-02 04:15:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// An event notifying the <see cref="PersistentEndpointClientConnector"/> that the connection has been closed
|
|
|
|
/// </summary>
|
2022-10-27 05:34:24 +00:00
|
|
|
public event Func<Exception?, Task>? Closed;
|
|
|
|
|
2022-11-02 04:15:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Notifies the <see cref="PersistentEndpointClientConnector"/> that the connection has been closed.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="exception">The exception that the connection closed with.</param>
|
2022-10-27 05:34:24 +00:00
|
|
|
protected Task InvokeClosed(Exception? exception) => Closed?.Invoke(exception) ?? Task.CompletedTask;
|
|
|
|
|
2022-11-02 04:15:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Connects the client to the remote service to begin processing messages.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="cancellationToken">A cancellation token to stop processing messages.</param>
|
2022-11-02 02:44:16 +00:00
|
|
|
public abstract Task ConnectAsync(CancellationToken cancellationToken);
|
2022-10-27 05:34:24 +00:00
|
|
|
|
|
|
|
public virtual ValueTask DisposeAsync()
|
|
|
|
{
|
|
|
|
Closed = null;
|
|
|
|
return new ValueTask(Task.CompletedTask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|