aya-lang / aya

Pocket sized programs
MIT License
54 stars 3 forks source link

Threading breaks `.U` and Canvas in AyaIDE #108

Open BlazingTwist opened 4 weeks ago

BlazingTwist commented 4 weeks ago

92 introduced an issue where the IDE seems to deadlock itself when opening Swing UI while running code from the editor.

Steps to reproduce

Results in: image


Probable cause:

https://github.com/aya-lang/aya/blob/3ab481f2eb3d14aac7d9a154db3c44a9bff12cf6/src/ui/EditorWindow.java#L224C4-L224C50

This is executed by the Swing Thread. Hence the Swing thread is waiting for the instruction to return. Which in turn is waiting for the Swing Thread to close the popup.


Possible fix

Wrapping it in a new Thread seems to work. I have not thought about possible side-effects this causes though

            new Thread(() -> {
                try {
                    ExecutionResult res = _aya.waitForResponse();
                    InteractiveAya.printResult(StaticData.IO, res);
                } catch (ThreadError e) {
                    StaticData.IO.err().print(e.getMessage());
                } catch (InterruptedException e) {
                    e.printStackTrace(StaticData.IO.err());
                }
            }).start();
nick-paul commented 4 weeks ago

I'm able to reproduce the issue with the dialog instructions as well.

Run in editor:

import ::dialog
"test" dialog.alert

Thanks for the report, I'll dig into this a bit more to see what the best solution would be.