Skip to content

Commit

Permalink
chore: simplify resourcerefparser async
Browse files Browse the repository at this point in the history
  • Loading branch information
ovska committed Oct 24, 2024
1 parent 70e48f6 commit 211e3aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Pack3r.Core/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 5 additions & 6 deletions Pack3r.Core/Parsers/ResourceRefParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ public async Task ParseReferences(
}
}

private Task<ResourceList?> TryParse(
private async Task<ResourceList?> TryParse(
Map map,
Resource resource,
CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
return Task.FromCanceled<ResourceList?>(cancellationToken);
cancellationToken.ThrowIfCancellationRequested();

IReferenceParser? parser = null;

Expand All @@ -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;
}
}

0 comments on commit 211e3aa

Please sign in to comment.