Skip to content

Commit

Permalink
Don't allow resolved Promises to starve the event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Oct 23, 2024
1 parent 16b0dc1 commit d37aaef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-horses-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nx.js/runtime": patch
---

Don't allow resolved Promises to starve the event loop
8 changes: 6 additions & 2 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,12 @@ int nx_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
void nx_process_pending_jobs(JSRuntime *rt) {
JSContext *ctx;
int err;
for (;;) {
// Don't allow an infinite number of pending jobs
// to allow the UI to update periodically. The number
// of iterations was chosen arbitrarily - maybe could
// be optimized by using a timer instead of a fixed
// number of iterations.
for (u8 i = 0; i < 20; i++) {
err = JS_ExecutePendingJob(rt, &ctx);
if (err <= 0) {
if (err < 0) {
Expand Down Expand Up @@ -507,7 +512,6 @@ int main(int argc, char *argv[]) {

print_console = consoleInit(NULL);

// rc = socketInitializeDefault();
rc = socketInitialize(&s_socketInitConfig);
if (R_FAILED(rc)) {
diagAbortWithResult(rc);
Expand Down

0 comments on commit d37aaef

Please sign in to comment.