void (@NotNull Runnable init, @NotNull CompletableFuture<?> stopCondition) { // "enter" modality init.run(); // wait for task future to complete try { stopCondition.get(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException(e); } throw t; }