Merge pull request #718 from ZaneYork/develop
Parallel exception aggregate fix
This commit is contained in:
commit
cfc7233a06
|
@ -57,12 +57,15 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
|
|||
/// <returns>Returns whether the module was modified.</returns>
|
||||
public bool RewriteModule()
|
||||
{
|
||||
bool anyRewritten = false;
|
||||
|
||||
foreach (TypeDefinition type in this.Module.GetTypes())
|
||||
Tuple<bool,Exception> aggregateResult = this.Module.GetTypes()
|
||||
.AsParallel().WithExecutionMode(ParallelExecutionMode.ForceParallelism)
|
||||
.Select(type =>
|
||||
{
|
||||
try
|
||||
{
|
||||
bool anyRewritten = false;
|
||||
if (type.BaseType == null)
|
||||
continue; // special type like <Module>
|
||||
return new Tuple<bool, Exception>(anyRewritten, null); // special type like <Module>
|
||||
|
||||
anyRewritten |= this.RewriteCustomAttributes(type.CustomAttributes);
|
||||
anyRewritten |= this.RewriteGenericParameters(type.GenericParameters);
|
||||
|
@ -108,9 +111,20 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return anyRewritten;
|
||||
return new Tuple<bool, Exception>(anyRewritten, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new Tuple<bool, Exception>(false, e.InnerException ?? e);
|
||||
}
|
||||
})
|
||||
.Aggregate((tupleA, tupleB) => new Tuple<bool, Exception>(tupleA.Item1 | tupleB.Item1, tupleA.Item2 ?? tupleB.Item2)); // Aggregate result and exception
|
||||
if (aggregateResult.Item2 != null)
|
||||
{
|
||||
throw aggregateResult.Item2; // rethrow inner Exception
|
||||
}
|
||||
return aggregateResult.Item1;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue