From b5ac05a8530386fb2650d8b0abbe44ab367fa9d8 Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Wed, 7 Aug 2024 19:05:41 +0200 Subject: [PATCH] chore: minor improvements --- .../PacketDistributorService.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) 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; } }