Closed qwenger closed 2 years ago
Hey this looks great! Let me see if I can find the time to review this properly this weekend. Thanks!
Note: with this patch, in the presence of potentially asynchronous code, the standard thing would be to call execute_pending_job
repeatedly:
ctx.eval("/* some job launching */")
while ctx.execute_pending_job():
pass
ctx.eval("/* some more code */")
If this back-and-forth between Python and JS is too slow, we could implement an execute_all_pending_jobs
method with a loop on the C side, just like js_std_loop
(https://github.com/bellard/quickjs/blob/master/quickjs-libc.c#L3878).
Fix #62.
Note that errors occurring in asynchronous code do not seem to be raised (even though the case
JS_ExecutePendingJob(...) < 0
is handled). But this seems to be the case in the nativeqjs
as well. EDIT: this seems to be a matter of usingJS_SetHostPromiseRejectionTracker
, see https://github.com/bellard/quickjs/issues/87. Should we use it, or maybe conditionally with a flag on the context (the question also applies to #64 ...)?