Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Fix #62: Implement async job execution#65

Merged
PetterS merged 5 commits intoPetterS:masterfrom
qwenger:feature_pending_jobs
Nov 23, 2021
Merged

Fix #62: Implement async job execution#65
PetterS merged 5 commits intoPetterS:masterfrom
qwenger:feature_pending_jobs

Conversation

@qwenger
Copy link
Collaborator

@qwenger qwenger commented Oct 23, 2021

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 native qjs as well.
EDIT: this seems to be a matter of using JS_SetHostPromiseRejectionTracker, see bellard/quickjs#87. Should we use it, or maybe conditionally with a flag on the context (the question also applies to #64 ...)?

@PetterS
Copy link
Owner

PetterS commented Oct 28, 2021

Hey this looks great! Let me see if I can find the time to review this properly this weekend. Thanks!

@qwenger
Copy link
Collaborator Author

qwenger commented Oct 31, 2021

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).

Copy link
Owner

@PetterS PetterS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

This should be useful

@PetterS PetterS merged commit e04d78c into PetterS:master Nov 23, 2021
@qwenger qwenger deleted the feature_pending_jobs branch April 2, 2022 12:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Asynchronous code

2 participants