Skip to content
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

await behave is not as expected #443

Closed
topelinux opened this issue Dec 17, 2023 · 4 comments · Fixed by #444
Closed

await behave is not as expected #443

topelinux opened this issue Dec 17, 2023 · 4 comments · Fixed by #444

Comments

@topelinux
Copy link
Contributor

following is the test code

//for quickjs verify
//import {setTimeout} from "os";
async function sleep(ms) {
    return new Promise(reslove => {
     setTimeout(reslove, ms);
    });
}

async function main() {
    console.log("before sleep");
    await sleep(1000);
    console.log('this is test');
}

main()
console.log("hi");

the output with tjs run is

before sleep
hi

the 'this is test' is no show as expected

use qjs the behavor is ok(after uncomment the import)

before sleep
hi
this is test
@saghul
Copy link
Owner

saghul commented Dec 17, 2023

What version of both did you test?

@topelinux
Copy link
Contributor Author

for tjs:
v23.12.0
the behavior is not as expected

for qjs:
QuickJS version 2021-03-27

FYI
tjs
v23.1.0 works as expected.

@saghul
Copy link
Owner

saghul commented Dec 17, 2023

Thanks! I'll investigate!

@saghul
Copy link
Owner

saghul commented Dec 17, 2023

Hum, looks like the libuv event loop finishes after the timer hits, and that's why the script stops. I need to figure out why that happens and what changed...

saghul added a commit that referenced this issue Dec 18, 2023
In libuv/libuv#3686 libuv changed when timers
run respective to check handles.

Change the way we run the loop by running it again if necessary, untill
there is no more work to do of the loop has been stopped.

Fixes: #443
saghul added a commit that referenced this issue Dec 18, 2023
In libuv/libuv#3686 libuv changed when timers
run respective to check handles.

Change the way we run the loop by running it again if necessary, untill
there is no more work to do of the loop has been stopped.

Fixes: #443
saghul added a commit that referenced this issue Dec 18, 2023
In libuv/libuv#3686 libuv changed when timers
run respective to check handles.

Change the way we run the loop by running it again if necessary, untill
there is no more work to do of the loop has been stopped.

Fixes: #443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants