Boolean () { boolean[] result = new boolean[1]; try { ProgressManager.getInstance().executeProcessUnderProgress(() -> { try { T element = myFirstTask; while (true) { if (element == null) element = things.take(); if (element == tombStone) { things.put(tombStone); // return just popped tombStone to the 'things' queue for everybody else to see it // since the queue is drained up to the tombStone, there surely should be a place for one element, so "put" will not block result[0] = true; break; } try (AccessToken ignored = ThreadContext.installThreadContext(myContext, true)) { ProgressManager.checkCanceled(); if (!thingProcessor.process(element)) { break; } } catch (RuntimeException|Error e) { if (logAllExceptions) { LOG.info("Failed to process " + element + ". Add too failed query.", e); System.out.println("Failed to process " + element + ". "+ ExceptionUtil.getThrowableText(e)); } throw e; } element = null; } } catch (InterruptedException e) { throw new RuntimeException(e); } }, progress); return result[0]; } finally { if (!result[0]) { futureResult.set(false); } completer.tryComplete(); } }