void (CancellationCheck cancellation, int period, int times, int depth) { Clock.setTime(1L); cancellation.withCancellationCheck(() -> { for (int attempt = 0; attempt < times * 2; attempt++) { myProgressIndicator.checkCanceled(); Clock.setTime(Clock.getTime() + period); if (depth - 1 > 0) { runWithCheckCancellation(cancellation, period, times, depth - 1); } } return null; }); }