+
+ // 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())
+ {
+ // if this is the last one then complete filesAllSaved
+ cf.whenComplete((ret, e) -> {
+ if (!BackupFiles.hasSavesInProgress())
+ {
+ filesAllSaved.complete(true);
+ }
+ });
+ }
+
+ final int waitTimeFinal = waitTime;
+ // timeout the wait -- will result in another wait button when looped
+ CompletableFuture<Boolean> waitTimeout = CompletableFuture
+ .supplyAsync(() -> {
+ executor.submit(() -> {
+ try
+ {
+ Thread.sleep(waitTimeFinal);
+ } catch (InterruptedException e)
+ {
+ // probably interrupted by all files saving
+ }
+ });
+ return true;
+ });
+ CompletableFuture<Object> waitForSave = CompletableFuture
+ .anyOf(waitTimeout, filesAllSaved);
+ Console.debug("##### WAITFORSAVE RUNNING");
+
+ QResponse waitResponse = QResponse.NULL;
+
+ int iteration = 0;
+ boolean doIterations = true;
+ while (doIterations && BackupFiles.hasSavesInProgress()
+ && iteration++ < (interactive ? 100 : 5))