Invoke runnable after another task finishes

Hello!
My plugin does some long calculations in order to later display calculated data in Editor. Therefore, when my FileOpenListener is invoked I need to somehow check are my calculations finished, and, if not, wait for them to finish and only after this display calculated data. 
So, I need something like "invoke if another task completed or wait until it completes". How can I do this? 
Thanks!

4 comments
Comment actions Permalink

I assume you mean com.intellij.openapi.fileEditor.FileEditorManagerListener#fileOpened.

Do you start calculating from there? What kind of data is displayed later and how is it applied to the editor?

0
Comment actions Permalink

No, calculation starts in my implementation of com.intellij.openapi.components.ProjectComponent on project opening. 

Data is added to Editor's InlayModel via block elements.

The easiest way in my opinion is to just check if data processing is finished in a while loop, but this seems not good. Therefore I want to know, if there is something out of the box in intellij-openapi, or should I use standart Java ExecutorService for this.

 

Thanks!

0
Comment actions Permalink

Does org.jetbrains.concurrency.Promises help?

0
Comment actions Permalink

Hi Yann!

I've solved this with

ApplicationManager.getApplication().executeOnPooledThread(() -> ...);

and passing Future returned by this method in FileOpenedHandler's constructor. So it works OK for now.

Thanks!

0

Please sign in to leave a comment.