mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Add the warmUp lifecycle hook and LifecycleRunner.warmUp
This commit is contained in:
1 parent
f6c078aade
commit
3c05cfea0a
6 files changed
+97
-5
No files matched your search
@@ -13,6 +13,7 @@ import java.util.Objects;
|
||||
* var lifecycles = new LifecycleRunner(pack.catalog());
|
||||
* lifecycles.packLoaded(resources, packSettings); // once per pack snapshot, before its first world starts
|
||||
* lifecycles.worldStarted(world); // before the world generates anything
|
||||
* lifecycles.warmUp(world); // then, possibly on another thread, before its first generation
|
||||
* ...
|
||||
* lifecycles.worldStopped(world); // then close the world's state
|
||||
* }</pre>
|
||||
@@ -60,6 +61,30 @@ public final class LifecycleRunner {
|
||||
}
|
||||
}
|
||||
|
||||
/** Runs every {@code warmUp} hook in order, each even when an earlier one threw; afterwards throws the first
|
||||
* failure, naming its module, with the later ones suppressed. The caller picks the thread and waits for this
|
||||
* before the world generates.
|
||||
*/
|
||||
public void warmUp(PackWorld world) {
|
||||
Objects.requireNonNull(world, "world");
|
||||
IllegalStateException failure = null;
|
||||
for (var registration : lifecycles) {
|
||||
try {
|
||||
registration.lifecycle().warmUp(world);
|
||||
} catch (RuntimeException warmFailure) {
|
||||
var named = failed("warming up a world", registration, warmFailure);
|
||||
if (failure == null) {
|
||||
failure = named;
|
||||
} else {
|
||||
failure.addSuppressed(named);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
/** Runs every {@code worldStopped} hook in reverse order, each even when an earlier one threw; afterwards throws the
|
||||
* first failure, naming its module, with the later ones suppressed.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user