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

Promises don't work #25

Closed
Tiagoperes opened this issue Dec 8, 2020 · 7 comments
Closed

Promises don't work #25

Tiagoperes opened this issue Dec 8, 2020 · 7 comments

Comments

@Tiagoperes
Copy link
Contributor

Tiagoperes commented Dec 8, 2020

version: 0.2.2+0

the following code never prints "after promise":

async function start() {
    console.log('before promise');
    await Promise.resolve('test');
    console.log('after promise');
}

In the flutter code, I call widget.jsRuntime.enableHandlePromises() and widget.jsRuntime.evaluate("start()");.

"before promise" is successfuly printed, but the execution hangs in the promise, even if it's already fulfilled. "after promise" is never printed.

Tested in Android

@Tiagoperes
Copy link
Contributor Author

Tiagoperes commented Dec 9, 2020

I also tried:

  • to remove widget.jsRuntime.enableHandlePromises();
  • previous versions of the lib;
  • different syntax (new Promise(resolve => resolve('test')))
  • to use generators/yield instead of async/await (transpilation with babel)

None of these approaches worked. They kept the same behavior, the execution stucked before "after promise" was printed.

@Tiagoperes
Copy link
Contributor Author

It does work if I force the use of JavascriptCore, which is weird, because the documentation of QuickJS states that it does support promises and its online demo works fine when I test the async code there.

@abner
Copy link
Owner

abner commented Dec 22, 2020

Hi @Tiagoperes. I will check

@cacard
Copy link

cacard commented Dec 26, 2020

me too

@PhungVanHoa
Copy link

@Tiagoperes you should call executePendingJob

@Tiagoperes
Copy link
Contributor Author

Tiagoperes commented Jan 4, 2021

@Tiagoperes you should call executePendingJob

@PhungVanHoa this wouldn't be viable in realistic scenarios. The example I gave is short and its only purpose is to demonstrate the problem. My real issue comes from the need to use a library that, internally relies in many promises. I have no control over these promises and I dont know when they're created. I shouldn't have to explicitly resolve them. Today, if you use the default implementation of flutter_js, the program hangs everytime a promise is created internally by the js lib, and, as I said, I have no way of knowing when a promise is created, I only have access to the API.

This is not problem for me anymore since I realized I could force JavascriptCore on Android and things would work as expected. But, in any case, I think it should also work with QuickJS.

@abner
Copy link
Owner

abner commented Apr 4, 2021

I released some improvements in QuickJS integration and it should work better now.
But you still need to keep the calling the executePendingJobs because QuickJS do added Promises support, but it does not have
a event loop running all the time. It evaluate the scripts you send to it, but to resolve promises you need to keep calling executePendingJobs in a regular interval.

There is not i could do better to help you with it.

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

No branches or pull requests

4 participants