Add the warmUp lifecycle hook and LifecycleRunner.warmUp

This commit is contained in:
piexel committed 2026-10-09 20:22:29 +02:00
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.
*/