Throw timeout exceptions instead

This commit is contained in:
smoogipoo 2020-03-16 11:33:26 +09:00
parent f390c1995d
commit 9c5423734a
1 changed files with 20 additions and 4 deletions

View File

@ -100,7 +100,9 @@ public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods
// Apply conversion mods
foreach (var mod in mods.OfType<IApplicableToBeatmapConverter>())
{
cancellationSource.Token.ThrowIfCancellationRequested();
if (cancellationSource.IsCancellationRequested)
throw new BeatmapLoadTimeoutException(BeatmapInfo);
mod.ApplyToBeatmapConverter(converter);
}
@ -115,7 +117,9 @@ public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
{
cancellationSource.Token.ThrowIfCancellationRequested();
if (cancellationSource.IsCancellationRequested)
throw new BeatmapLoadTimeoutException(BeatmapInfo);
mod.ApplyToDifficulty(converted.BeatmapInfo.BaseDifficulty);
}
}
@ -127,7 +131,9 @@ public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods
// Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
foreach (var obj in converted.HitObjects)
{
cancellationSource.Token.ThrowIfCancellationRequested();
if (cancellationSource.IsCancellationRequested)
throw new BeatmapLoadTimeoutException(BeatmapInfo);
obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty);
}
@ -135,7 +141,9 @@ public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods
{
foreach (var obj in converted.HitObjects)
{
cancellationSource.Token.ThrowIfCancellationRequested();
if (cancellationSource.IsCancellationRequested)
throw new BeatmapLoadTimeoutException(BeatmapInfo);
mod.ApplyToHitObject(obj);
}
}
@ -315,5 +323,13 @@ public T Value
private void recreate() => lazy = new Lazy<T>(valueFactory, LazyThreadSafetyMode.ExecutionAndPublication);
}
private class BeatmapLoadTimeoutException : TimeoutException
{
public BeatmapLoadTimeoutException(BeatmapInfo beatmapInfo)
: base($"Timed out while loading beatmap ({beatmapInfo}).")
{
}
}
}
}