package market.guess.ui.desktop.task; import java.nio.file.Path; import javafx.concurrent.Task; import market.guess.api.CatalogContext; import market.guess.api.LoadResult; public final class InitialLoadTask extends Task { private final CatalogContext catalog; private final Path path; public InitialLoadTask(CatalogContext catalog, Path path) { this.catalog = catalog; this.path = path; } @Override protected LoadResult call() throws Exception { updateProgress(0, 100); if (isCancelled()) { return null; } for (int i = 0; i < 20; i++) { if (isCancelled()) { return null; } try { Thread.sleep(100); } catch (InterruptedException e) { if (isCancelled()) { return null; } Thread.currentThread().interrupt(); break; } updateProgress((i + 1) * 5, 100); } if (isCancelled()) { return null; } var result = catalog.loadEvents(path); if (isCancelled()) { return null; } if (!result.isSuccess()) { throw new RuntimeException(result.getDetails()); } updateProgress(100, 100); return result.getData(); } }