Async Promise Execution in quickjs runs in the same thread #948
-
In Node.js, when executing multiple asynchronous tasks using Promise.all([...tasks]), the tasks can run in parallel (if they involve I/O or worker threads). However, in QuickJS, it seems that Promise.all([...tasks]) still runs everything sequentially in the same thread, making async execution feel less useful. An example: let tasks = [];
// Push some tasks as Promise to the tasks array
await Promise.all(tasks); Since quickjs runs js in a single thread, promises seem to be resolved synchronously in the same event loop. Is it possible to achieve the asynchronous tasks like Nodejs? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It seems difficult to run javascript code involving potentially shared objects concurrently in different threads. I don't know if node does it but I do not think QuickJS can do this without substantial work. |
Beta Was this translation helpful? Give feedback.
-
Speaking as someone who is substantially responsible for making Node.js what it is today: promises - and, by extension, Promise.all - work exactly the same in Node.js and QuickJS. It sounds like you're conflating the general concept of promises with specific tasks (like file operations) that get offloaded to a native thread pool but that's no different from what you can do with QuickJS... ...and is in fact what our @saghul does with txiki.js. It's basically QuickJS + libuv, the event loop and I/O library backing Node.js. |
Beta Was this translation helpful? Give feedback.
Speaking as someone who is substantially responsible for making Node.js what it is today: promises - and, by extension, Promise.all - work exactly the same in Node.js and QuickJS.
It sounds like you're conflating the general concept of promises with specific tasks (like file operations) that get offloaded to a native thread pool but that's no different from what you can do with QuickJS...
...and is in fact what our @saghul does with txiki.js. It's basically QuickJS + libuv, the event loop and I/O library backing Node.js.