-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible to write a script with async elements #137
Comments
This might be a limitation in the |
From what I understand, this may be solveable with a bit of inspiration from this article. The gist of it would be :
|
I'd like to take a go at my proposal above, but I have no experience in java, and I have no idea how to compile the JArchi project |
Hi, I'll have a look at it. |
Hello again! With help from the documentation and Graal's own unit tests, I have attempted the following :
As you can see, an error gets thrown uppon launching an async process. The error doesn't really tell me what's going on either ... I'll try some other code ideas, but I have a feeling that this issue might be solved by switching to a newer version of Graal/GraalJS. @jbsarrodie, have you had the time to take a look at this issue ? Do you have some leads ? |
One thing that concerns me is whether using asynchronous code will mess up the order of commands. This is important for undo/redo and getting things in the right order. |
In my case, I'm tasked with creating a JArchi plugin that generates a PowerPoint presentation from Archi's model. |
I've pushed a new branch |
Okay, so uh ... The Java code I posted 4 hours ago actually works, It's just that GraalJS doesn't support With that in mind, @Phillipus, if you try the same const JavaThread = Java.type("java.lang.Thread");
var setTimeout = (callback, ms, ...args) => {
JavaThread.sleep(ms)
if (args.length) callback(...args)
else callback()
} |
Hi,
I've just had a look and:
So it it seems that for case 1 it was only related to setTimeout For case 2, I can reproduce the error, even with a slightly more recent version of graalvm (22.3.4) that I use for some other purposes.
So it seems that a recent version of graalvm is not enough to solve case 2. BTW, @Phillipus we should really upgrade graalvm, several issues that I faced in the past were related to it, so I used a patched version. Because I was using an old version of jArchi (1.5), I didn't noticed 1.7 was still using the same. In addition, we should also add
It shouldn't have any impact, because all changes are done inside the same thread and recorded in the undo stack in the order they were really done. I did some basic tests that tend to prove it. |
Do you think you'll implement a similar class in principle to what I have proposed Friday into a future release of JArchi ? |
I can get Case 1 and Case 2 working by (a) providing the const JavaThread = Java.type("java.lang.Thread");
var setTimeout = (callback, ms, ...args) => {
JavaThread.sleep(ms)
if (args.length) callback(...args)
else callback()
}
console.log("case 1. starting synchronous part");
new Promise((resolve) => {
console.log("case 1. starting async part");
setTimeout(resolve, 1000);
}).then(() => console.log("case 1. async part ended"));
console.log("case 1. synchronous part ended");
async function start() {
await new Promise((resolve) => {
console.log("case 2. starting async part");
setTimeout(resolve, 1000);
})
console.log("case 2. async part ended");
}
console.log("case 2. starting synchronous part");
start(); |
jArchi Version
1.7
Archi Version
5.4.2
Operating System
Linux Mint Cinnamon 64bit
Description
Async scenarios lead to the following checkmate :
org.graalvm.polyglot.PolyglotException
is raisedSteps to reproduce
Case 1:
In this case, the JArchi console only prints:
"starting synchronous part"
"starting async part"
"synchronous part ended"
=>
"async part ended"
is never printedCase 2:
There, the console displays the following error:
The text was updated successfully, but these errors were encountered: