better async js support
This commit is contained in:
parent
64f620c078
commit
b7182511bf
3 changed files with 25 additions and 5 deletions
|
|
@ -19,13 +19,20 @@ test -f "$1" && {
|
||||||
|
|
||||||
OUTPUT=/mnt/run/$PID # com/isoterminal/feat/javascript.js writes output here
|
OUTPUT=/mnt/run/$PID # com/isoterminal/feat/javascript.js writes output here
|
||||||
|
|
||||||
touch $OUTPUT
|
|
||||||
echo -n "PID=$PID; $javascript" > /dev/browser/js
|
echo -n "PID=$PID; $javascript" > /dev/browser/js
|
||||||
# todo watch file
|
|
||||||
sleep 0.1
|
|
||||||
cat $OUTPUT
|
|
||||||
rm $OUTPUT
|
|
||||||
|
|
||||||
|
# check for file output
|
||||||
|
check_ready(){
|
||||||
|
test -f $OUTPUT && {
|
||||||
|
cat $OUTPUT | grep -vE '^undefined$';
|
||||||
|
code="$(cat ${OUTPUT}.exit)"
|
||||||
|
rm $OUTPUT;
|
||||||
|
exit $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
check_ready
|
||||||
|
while sleep 0.3; do check_ready; done
|
||||||
|
|
||||||
# should we use flock, an awesome way to make processes read/write the same file
|
# should we use flock, an awesome way to make processes read/write the same file
|
||||||
# while preventing 1001 concurrency issues?
|
# while preventing 1001 concurrency issues?
|
||||||
|
|
|
||||||
|
|
@ -251,3 +251,16 @@ Various options:
|
||||||
3. Run `jsh alert hello` in the shell
|
3. Run `jsh alert hello` in the shell
|
||||||
4. Run `jsh` to start an interactive shell
|
4. Run `jsh` to start an interactive shell
|
||||||
|
|
||||||
|
This allow writing (a)synchronous cli-scripts which execute in the browser:
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/js
|
||||||
|
return "hello"
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/js
|
||||||
|
return new Promise( (resolve,reject) => resolve("hello") )
|
||||||
|
```
|
||||||
|
|
||||||
|
NOTE: For convenience the javascript-code is passed to browser-context (via the webworker). In the future a package like [quickjs](https://bellard.org/quickjs/) will isolate things further.
|
||||||
|
|
|
||||||
BIN
dist/v86-linux.iso
vendored
BIN
dist/v86-linux.iso
vendored
Binary file not shown.
Loading…
Add table
Reference in a new issue