A file deadlock.mjs with this in it:
await new Promise(function(resolve) {});
will run and immediately end giving an exit code of 13. I would've expected this program to hang forever.
await new Promise(function(resolve) {resolve()});
unsurprisingly ends immediately and gives a 0 exit code.
Why doesn't the first program deadlock? And what is the significance of exit code 13?
Node isn't deadlocking because it's noticing that it's not waiting on anything. Here's a great explanation of how it notices that. But because you've used a top-level await here, Node knows that it's exiting abnormally and gives a 13 exit code:
13Unfinished Top-Level Await:awaitwas used outside of a function in the top-level code, but the passedPromisenever resolved.
https://nodejs.org/api/process.html#exit-codes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With