void (@NotNull Runnable runnable, @NotNull ModalityState modalityState) { if (isDispatchThread()) { runIntendedWriteActionOnCurrentThread(runnable); return; } if (EDT.isCurrentThreadEdt()) { runIntendedWriteActionOnCurrentThread(runnable); return; } if (holdsReadLock()) { throw new IllegalStateException("Calling invokeAndWait from read-action leads to possible deadlock."); } Runnable r = myTransactionGuard.wrapLaterInvocation(AppScheduledExecutorService.capturePropagationAndCancellationContext(runnable), modalityState); LaterInvocator.invokeAndWait(modalityState, wrapWithRunIntendedWriteAction(r)); }