boolean (long msTimeout) { if (isProcessed()) { return true; } Semaphore semaphore = new Semaphore(); semaphore.down(); doWhenProcessed(() -> semaphore.up()); try { if (msTimeout == -1) { semaphore.waitForUnsafe(); } else if (!semaphore.waitForUnsafe(msTimeout)) { reject("Time limit exceeded"); return false; } } catch (InterruptedException e) { reject(e.getMessage()); return false; } return true; }