- // future that returns a Boolean when all files are saved
- CompletableFuture<Boolean> filesAllSaved = new CompletableFuture<>();
-
- // callback as each file finishes saving
- for (CompletableFuture<Boolean> cf : BackupFiles
- .savesInProgressCompletableFutures(false))
- {
- // if this is the last one then complete filesAllSaved
- cf.whenComplete((ret, e) -> {
- if (!BackupFiles.hasSavesInProgress())
- {
- filesAllSaved.complete(true);
- }
- });
- }
-
- // timeout the wait -- will result in another wait button when looped
- CompletableFuture<Boolean> waitTimeout = CompletableFuture
- .supplyAsync(() -> {
- Console.debug("################# STARTING WAIT SLEEP");
- try
- {
- Thread.sleep(waitTimeFinal);
- } catch (InterruptedException e)
- {
- // probably interrupted by all files saving
- }
- return true;
- });
- CompletableFuture<Object> waitForSave = CompletableFuture
- .anyOf(waitTimeout, filesAllSaved);
-