// This file is provided under The MIT License as part of RiptideNetworking.
// Copyright (c) Tom Weiland
// For additional information please see the included LICENSE.md file or view it on GitHub:
// https://github.com/RiptideNetworking/Riptide/blob/main/LICENSE.md
using Riptide.Transports;
namespace Riptide.Utils
{
/// Executes an action when invoked.
internal abstract class DelayedEvent
{
/// Executes the action.
public abstract void Invoke();
}
/// Resends a when invoked.
internal class ResendEvent : DelayedEvent
{
/// The message to resend.
private readonly PendingMessage message;
/// The time at which the resend event was queued.
private readonly long initiatedAtTime;
/// Initializes the event.
/// The message to resend.
/// The time at which the resend event was queued.
public ResendEvent(PendingMessage message, long initiatedAtTime)
{
this.message = message;
this.initiatedAtTime = initiatedAtTime;
}
///
public override void Invoke()
{
if (initiatedAtTime == message.LastSendTime) // If this isn't the case then the message has been resent already
message.RetrySend();
}
}
/// Executes a heartbeat when invoked.
internal class HeartbeatEvent : DelayedEvent
{
/// The peer whose heart to beat.
private readonly Peer peer;
/// Initializes the event.
/// The peer whose heart to beat.
public HeartbeatEvent(Peer peer)
{
this.peer = peer;
}
///
public override void Invoke()
{
peer.Heartbeat();
}
}
}