diff --git a/RaiNote.PacketMediator/PacketDistributorService.cs b/RaiNote.PacketMediator/PacketDistributorService.cs index 3b564c2..65f4938 100644 --- a/RaiNote.PacketMediator/PacketDistributorService.cs +++ b/RaiNote.PacketMediator/PacketDistributorService.cs @@ -13,13 +13,15 @@ public class PacketDistributorService : IHostedService public PacketDistributorService(IServiceProvider serviceProvider, IEnumerable sourcesContainingPackets, IEnumerable sourcesContainingPacketHandlers) { - _packetDistributor = new PacketDistributor(serviceProvider, sourcesContainingPackets, - sourcesContainingPacketHandlers); + _packetDistributor = new PacketDistributor(serviceProvider, + sourcesContainingPackets, + sourcesContainingPacketHandlers + ); } - public Task StartAsync(CancellationToken cancellationToken) + public async Task StartAsync(CancellationToken cancellationToken) { - return _packetDistributor.DequeuePacketAsync(cancellationToken); + await _packetDistributor.DequeuePacketAsync(cancellationToken); } public Task StopAsync(CancellationToken cancellationToken) @@ -32,15 +34,10 @@ public class PacketDistributorService : IHostedService return _packetDistributor.AddPacketAsync(packetData, operationCode, session); } - public TPacketIdEnum GetOperationCodeByPacketType(IPacket packet) + public DotNext.Optional GetOperationCodeByPacketType(IPacket packet) { var type = packet.GetType(); _packetDistributor.PacketIdMap.TryGetValue(type, out var value); - if (value is null) - { - throw new ArgumentOutOfRangeException(type.Name); - } - - return value; + return value ?? DotNext.Optional.None; } }