void (@NotNull Document document) { Application app = ApplicationManager.getApplication(); if (!app.isDispatchThread() && isEventSystemEnabled(document)) { // have to run in EDT to guarantee data structure safe access and "execute in EDT" callbacks contract app.invokeLater(()-> { if (!myProject.isDisposed() && isCommitted(document)) { runAfterCommitActions(document); } }); return; } Runnable[] list = getAndClearActionsAfterCommit(document); try (AccessToken ignored = ThreadContext.resetThreadContext()) { for (Runnable runnable : list) { runnable.run(); } } if (app.isDispatchThread()) { runActionsWhenAllCommitted(); } else if (isEventSystemEnabled(document)) { app.invokeLater(() -> runActionsWhenAllCommitted(), myProject.getDisposed()); } }