archimatetool / archimatetool/archi-scripting-plugin
Impossible to write a script with async elements
- Dominant language
- Java
- Stars
- 171
- Forks
- 51
- PR merge metrics
- No merged PRs in 30d
Description
### jArchi Version
1.7
### Archi Version
5.4.2
### Operating System
Linux Mint Cinnamon 64bit
### Description
Async scenarios lead to the following checkmate :
- **Case 1:** If a promise is pending, but the synchronous part of the code is finished, the entire script is ended, before the promise can finish
- **Case 2:** If a top level await is written, `org.graalvm.polyglot.PolyglotException` is raised
### Steps to reproduce
- **Case 1:**
```js
console.log("starting synchronous part");
new Promise((resolve) => {
console.log("starting async part");
setTimeout(resolve, 1000);
}).then(() => console.log("async part ended"));
console.log("synchronous part ended");
```
In this case, the JArchi console only prints:
- `"starting synchronous part"`
- `"starting async part"`
- `"synchronous part ended"`
=> `"async part ended"` is never printed
- **Case 2:**
```js
console.log("starting synchronous part");
await new Promise((resolve) => {
console.log("starting async part");
setTimeout(resolve, 1000);
})
console.log("async part ended");
```
There, the console displays the following error:
```error
org.graalvm.polyglot.PolyglotException: SyntaxError: Test.ajs:3:6 Expected ; but found new
await new Promise((resolve) => {
^
Test.ajs:6:0 Expected eof but found }
}).then(() => console.log("async part ended"));
^
at .:program(:1)
at org.graalvm.polyglot.Context.eval(Context.java:399)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:478)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:446)
at java.scripting/javax.script.AbstractScriptEngine.eval(Unknown Source)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.