From 211e3aa3ffb4d4a62357f3ce37622863a805aa44 Mon Sep 17 00:00:00 2001 From: ovska Date: Thu, 24 Oct 2024 19:58:11 +0300 Subject: [PATCH] chore: simplify resourcerefparser async --- Pack3r.Core/Logging/Logger.cs | 2 +- Pack3r.Core/Parsers/ResourceRefParser.cs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Pack3r.Core/Logging/Logger.cs b/Pack3r.Core/Logging/Logger.cs index b754a60..7920a94 100644 --- a/Pack3r.Core/Logging/Logger.cs +++ b/Pack3r.Core/Logging/Logger.cs @@ -91,7 +91,7 @@ public void Drain() lock (Global.ConsoleLock) { - foreach (var message in messages) + foreach (ref var message in messages) { LogInternalNoLock(message.Level, message.Message, message.Context); } diff --git a/Pack3r.Core/Parsers/ResourceRefParser.cs b/Pack3r.Core/Parsers/ResourceRefParser.cs index 29ebb63..a608781 100644 --- a/Pack3r.Core/Parsers/ResourceRefParser.cs +++ b/Pack3r.Core/Parsers/ResourceRefParser.cs @@ -89,13 +89,12 @@ public async Task ParseReferences( } } - private Task TryParse( + private async Task TryParse( Map map, Resource resource, CancellationToken cancellationToken) { - if (cancellationToken.IsCancellationRequested) - return Task.FromCanceled(cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); IReferenceParser? parser = null; @@ -111,18 +110,18 @@ public async Task ParseReferences( if (parser is null) { logger.Warn($"Unsupported reference resource type: {resource}"); - return Task.FromResult(default(ResourceList)); + return null; } foreach (var source in map.AssetSources) { if (source.Assets.TryGetValue(resource.Value, out IAsset? asset)) { - return parser.Parse(asset, cancellationToken); + return await parser.Parse(asset, cancellationToken); } } logger.Warn($"Can't resolve files used by {parser.Description}, file not found: '{resource.Value}'"); - return Task.FromResult(default(ResourceList)); + return null; } }