//
// FakePacketHandler.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Threading;
using System.Threading.Tasks;
using NosSmooth.Core.Packets;
using NosSmooth.Packets;
using Remora.Results;
namespace NosSmooth.Core.Tests.Fakes.Packets;
///
/// Fake Responder of a packet.
///
/// The packet to respond to.
public class FakePacketResponder : IPacketResponder
where TPacket : IPacket
{
private readonly Func, Result> _handler;
///
/// Initializes a new instance of the class.
///
/// The function respond handler.
public FakePacketResponder(Func, Result> handler)
{
_handler = handler;
}
///
public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default)
=> Task.FromResult(_handler(packetArgs));
}