Class MenuWorkers

java.lang.Object
dev.xichil.mvui.MenuWorkers

public final class MenuWorkers extends Object
Where backends run UiHost.runAsync(Callable, BiConsumer) tasks: one daemon thread per mod, so a mod whose task hangs (store IO waiting on another instance's file lock) holds up only its own menu. Each mod's tasks run one at a time, in the order they were started. A thread ends after a minute without work and comes back with the next task. Threads are daemons named "Xi's Multiversion UI: <modid>", so they never keep the game from exiting and are easy to find in a thread dump.

For backends; mods use UiHost.runAsync(Callable, BiConsumer). A backend's runAsync runs the task like this:

MenuWorkers.forTask(task).execute(() -> {
    T result = null;
    Throwable error = null;
    try {
        result = task.call();
    } catch (Throwable t) {
        error = t;
    }
    // back to the main thread: onDone.accept(result, error), then refresh
});
  • Method Details

    • forTask

      public static Executor forTask(Callable<?> task)
      The executor for task, as passed to a backend's UiHost.runAsync(Callable, BiConsumer): its mod's own single thread (Failsafe marks a registered menu's tasks with the mod id), or a shared one for tasks of no mod.
      Parameters:
      task - the task a backend's runAsync received
      Returns:
      a single-threaded executor; the same one for every task of the same mod