void (Disposable parent, Invoker invoker, Consumer<CancellablePromise<?>> interrupt) { InfiniteTask task = new InfiniteTask(interrupt == null); CancellablePromise<?> promise = invoker.invokeLater(task, 10); try { wait(task.started, "cannot start infinite task"); if (interrupt != null) interrupt.accept(promise); wait(task.finished, "cannot interrupt " + parent + " infinite task"); Assert.assertFalse("too long", task.infinite); } finally { promise.cancel(); if (!Disposer.isDisposed(parent)) { Disposer.dispose(parent); } } }