PetterS / quickjs

Thin Python wrapper of https://bellard.org/quickjs/
https://github.com/bellard/QuickJS
MIT License
175 stars 19 forks source link

Promise .any support #118

Closed lygstate closed 2 years ago

qwenger commented 2 years ago

Hi,

Please provide more information about what you tried, what didn't work, etc.

Promise.any is supported. Simply, being an asynchronous feature, one needs to use Context.execute_pending_job for it to be actually ran.

Example:

import quickjs

c = quickjs.Context()

c.eval("""
a = 0;

Promise.any([
    Promise.resolve().then(() => {globalThis.a = 1;}),
    Promise.resolve().then(() => {globalThis.a = 2;}),
]);
""")

assert c.get("a") == 0

while c.execute_pending_job():
    pass

assert c.get("a") > 0
qwenger commented 2 years ago

@lygstate Are you satisfied with the answer above? If so, I'll close this issue.