From d37aaef252f2289abfb7202e732a39c48cda2615 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 22 Oct 2024 23:37:39 -0700 Subject: [PATCH] Don't allow resolved Promises to starve the event loop --- .changeset/ten-horses-breathe.md | 5 +++++ source/main.c | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/ten-horses-breathe.md diff --git a/.changeset/ten-horses-breathe.md b/.changeset/ten-horses-breathe.md new file mode 100644 index 00000000..1b1c7299 --- /dev/null +++ b/.changeset/ten-horses-breathe.md @@ -0,0 +1,5 @@ +--- +"@nx.js/runtime": patch +--- + +Don't allow resolved Promises to starve the event loop diff --git a/source/main.c b/source/main.c index f1457d78..84ab01ce 100644 --- a/source/main.c +++ b/source/main.c @@ -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) { @@ -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);